Home > Backend Development > PHP Tutorial > Sample code sharing on how to use PHP in Dede

Sample code sharing on how to use PHP in Dede

黄舟
Release: 2023-03-07 06:38:01
Original
2480 people have browsed it

1. Basic usage:

{dede:field.descriptionrunphp='yes'}
if(@me<>&#39;&#39; )
@me = &#39;<div class="intro">&#39;.@me.&#39;</div>&#39;;
{/dede:field.description}


{dede:field name=&#39;imgurls&#39; alt=&#39;图片输出区&#39;}
[field:pagestylerunphp=&#39;yes&#39;] @me= (@me==3 ? &#39;<li>&#39; : &#39;&#39;);[/field:pagestyle]
<a href=&#39;[field:linkurl/]&#39; [field:pagestyle runphp=&#39;yes&#39;] @me= (@me==3 ? &#39;class="pic"&#39; : &#39;&#39;); [/field:pagestyle]>
<img src=&#39;[field:imgsrc/]&#39; id=&#39;bigimg&#39; [field:imgwidth /] alt=&#39;[field:alttext /]&#39; border=&#39;0&#39; />
</a>
<a href=&#39;[field:linkurl/]&#39; [field:pagestyle runphp=&#39;yes&#39;]@me = (@me==3 ? &#39;class="title"&#39; : &#39;&#39;);[/field:pagestyle]>
[field:title /]
</a>
[field:pagestyle runphp=&#39;yes&#39;] @me = (@me==3 ? &#39;</li>&#39; : &#39;&#39;); [/field:pagestyle]
{/dede:field}
Copy after login

2. Advanced usage:

1. dede background->System->System Settings->Basic System Parameters->Other options ->Remove the "php" tag in "Template EngineDisabled Tag" and save

2. Use:

{dede:php}
echo &#39;php&#39;;
{/dede:php}

{dede:php}
$result = mysql_query("select * from bbs_forum_forum t1 left join bbs_forum_forumfield t2 on t1.fid=t2.fid where status=1 and 
type=&#39;forum&#39; order by t1.displayorder asc");
while($row = mysql_fetch_assoc($result)){
     echo &#39;<table cellpadding="0" cellspacing="0" width="100%" border="0" class="pbw_bbsTable">&#39;;
     echo &#39;<tr>&#39;;
     echo &#39;<td width="64">&#39;;
     echo &#39;<a href="/bbs/forum.php?mod=forumdisplay&fid=&#39;.$row[&#39;fid&#39;].&#39;">
     <img src="/bbs/data/attachment/common/&#39;.$row[&#39;icon&#39;].&#39;" width="46" height="46" style="border:1px solid #000;" /></a>&#39;;
     echo &#39;</td>&#39;;
     echo &#39;<td width="465">&#39;;
     echo &#39;<div class="pbw_bbsTitle"><a href="/bbs/forum.php?mod=forumdisplay&fid=&#39;.$row[&#39;fid&#39;].&#39;">&#39;.$row[&#39;name&#39;].&#39;</a><span>(&#39;.$row[&#39;threads&#39;].&#39;)</span></div>&#39;;
     echo &#39;<div class="pbw_bbsBrief">&#39;.$row[&#39;description&#39;].&#39;</div>&#39;;
     echo &#39;<div style="color:red;">&#39;.$row[&#39;rules&#39;].&#39;</div>&#39;;
     $moderators = explode("    ", $row[&#39;moderators&#39;]);
     $moderators = implode(",", $moderators);
     echo &#39;<div class="pbw_bbsBanzhu">版主:&#39;.$moderators.&#39;</div>&#39;;
     echo &#39;</td>&#39;;
     echo &#39;<td width="90"> </td>&#39;;
     echo &#39;<td width="120" align="center">&#39;;
     echo $row[&#39;threads&#39;].&#39;/&#39;.$row[&#39;posts&#39;];
     echo &#39;</td>&#39;;
     echo &#39;<td>&#39;;
     $lastpost = explode("    ", $row[&#39;lastpost&#39;]);
     echo &#39;<a href="/bbs/forum.php?mod=viewthread&tid=&#39;.$lastpost[0].&#39;#lastpost">&#39;.$lastpost[1].&#39;</a>
     (<a href="/bbs/home.php?mod=space&username=&#39;.$lastpost[3].&#39;" style="color:#369">&#39;.$lastpost[3].&#39;</a>)<br />&#39;;
     echo date("Y-m-d H:i:s", $lastpost[2]);
     echo &#39;</td>&#39;;
     echo &#39;</tr>&#39;;
     echo &#39;</table>&#39;;
}
{/dede:php}
Copy after login

The above is the detailed content of Sample code sharing on how to use PHP in Dede. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template