search
HomeBackend DevelopmentPHP Tutorial 求{dede:sql}标签脚本内写php原生代码的步骤

求{dede:sql}标签脚本内写php原生代码的方法!
{dede:sql sql='...' runphp='yes'}

echo 'fuck';

{/dede:sql}

我这么写没用,应该怎样才可以在 {dede:sql}标签脚本内写php原生代码 ??

------解决方案--------------------
以下是dede中的php应用,希望对你有帮助
调用tag: {dede:field name='keywords' runphp='yes' }
if(!empty(@me)){
$kws = explode(' ',@me);
@me = "";
foreach($kws as $k){
@me .= "$k ";
}
@me= str_replace('+', ' ',trim(@me));
}
{/dede:field} 
dede在首页调用文章内容 
-------------------------------------------------
方法一:{dede:sql sql="SELECT aid,typeid,body,body1, body2,body3,body4,body5 FROM 
`dede_addonarticle` where typeid=2 ORDER BY `aid` DESC LIMIT 0 , 1"}
[field:body /] [field:body1 /] [field:body2 /] [field:body3 /] [field:body4 /] [field:body5 
/]
{/dede:sql}
方法二:{dede:sql sql="SELECT aid,typeid,body FROM `dede_addonarticle` where typeid=2 ORDER 
BY `aid` DESC LIMIT 0 , 1"}
[field:body /]
{/dede:sql}
调用说明:其中typeid=2,栏目ID号,表示调用此ID栏目内的文章,换成aid=1则表示调用的aid为1的文
章(具体哪篇文章aid是多少,要进数据库看,从后台看也可以),DESC表示排序,按从大到小排,换成
ASC则按从小到大排序,LIMIT 0 , 1表示调用数量,也可以写成数量LIMIT 1,这个1代表调用的数量。


列表隔5行加一行线: 
{dede:list pagesize='50'}

  • target=_blank>[field:title function="cn_substr(@me,48)"/][field:pubdate 
    runphp='yes'] 
    $a="".strftime('%m-%d',@me)."";
    $b=strftime('%m-%d',@me);
    $ntime = time(); 
    $day3 = 3600 * 24;
    if(($ntime - @me) else @me =$b; 
    [/field:pubdate]

    [field:global name=autoindex runphp="yes"]
    if(@me%5==0)@me="
    ";
    else @me="";
    [/field:global]
    {/dede:list}
  •  
    --------------------------------------------
    最新 文章列表 “隔行换色” 的方法 
    {dede:arclist orderby=pubdate titlelen='26' row='10'} 
    [field:global runphp='yes' name=autoindex]
    $a="
    ";
    $b="
    ";
    if ((@me%2)==0) @me=$a;
    else @me=$b;
    [/field:global] 

    • [field:title/]



    {/dede:arclist} 
    --------------------------------------------
    广告代码::{dede:myad name='广告位标识'/}
    24小时内更新的文章时间显示为红色: 
    [field:pubdate runphp='yes'] 
    $a="".strftime('%m-%d',@me)."";
    $b=strftime('%m-%d',@me);
    $ntime = time(); 
    $day3 = 3600 * 24;
    if(($ntime - @me) else @me =$b; 
    [/field:pubdate] 
    实现“文章标题-2级栏目-1级栏目-网站名”形式 
    {dede:field name='title'/}-{dede:field name='position' runphp='yes'}
    $tc="-"; //分隔符
    $tw=$GLOBALS['cfg_list_symbol']; //调用位置分隔符
    @me=html2text(@me); //去除html标签
    $tf=split($tw,@me); //分解成数组
    for($ta=(count($tf)-2);$ta>=1;$ta--){ //循环赋值给$tk
    $tk.=trim($tf[$ta]).$tc;
    }
    $tk=substr($tk,0,-1);
    @me=$tk; //赋值给@me
    {/dede:field}-{dede:global name='cfg_webname'/}

    发布的文章显示红色日期或加上new字或new小图片
    给近三天(或当天)发布的文章显示红色日期或加上new字或new小图片等。
    都是围绕pubdate做文章,写扩展的。
    第2、3要注意的问题是:如:" 求{dede:sql}标签脚本内写php原生代码的步骤 中不能用双引号,否则不行。
    如果要给当天的加,把 3600 * 24 * 3 改为 3600 * 24  即可。
    1、==========红色的日期========
    [field:pubdate runphp='yes'] 
    $a="".strftime('%m-%d',@me)."";
    $b=strftime('%m-%d',@me);
    $ntime = time(); 
    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

    PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

    How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

    The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

    Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

    CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

    Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

    Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

    What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

    ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

    Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

    The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

    PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

    PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

    PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

    ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    DVWA

    DVWA

    Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!

    Atom editor mac version download

    Atom editor mac version download

    The most popular open source editor

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.