Home > Article > Backend Development > Sample code sharing on how to use PHP in Dede
1. Basic usage:
{dede:field.descriptionrunphp='yes'} if(@me<>'' ) @me = '<div class="intro">'.@me.'</div>'; {/dede:field.description} {dede:field name='imgurls' alt='图片输出区'} [field:pagestylerunphp='yes'] @me= (@me==3 ? '<li>' : '');[/field:pagestyle] <a href='[field:linkurl/]' [field:pagestyle runphp='yes'] @me= (@me==3 ? 'class="pic"' : ''); [/field:pagestyle]> <img src='[field:imgsrc/]' id='bigimg' [field:imgwidth /] alt='[field:alttext /]' border='0' /> </a> <a href='[field:linkurl/]' [field:pagestyle runphp='yes']@me = (@me==3 ? 'class="title"' : '');[/field:pagestyle]> [field:title /] </a> [field:pagestyle runphp='yes'] @me = (@me==3 ? '</li>' : ''); [/field:pagestyle] {/dede:field}
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 'php'; {/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='forum' order by t1.displayorder asc"); while($row = mysql_fetch_assoc($result)){ echo '<table cellpadding="0" cellspacing="0" width="100%" border="0" class="pbw_bbsTable">'; echo '<tr>'; echo '<td width="64">'; echo '<a href="/bbs/forum.php?mod=forumdisplay&fid='.$row['fid'].'"> <img src="/bbs/data/attachment/common/'.$row['icon'].'" width="46" height="46" style="border:1px solid #000;" /></a>'; echo '</td>'; echo '<td width="465">'; echo '<div class="pbw_bbsTitle"><a href="/bbs/forum.php?mod=forumdisplay&fid='.$row['fid'].'">'.$row['name'].'</a><span>('.$row['threads'].')</span></div>'; echo '<div class="pbw_bbsBrief">'.$row['description'].'</div>'; echo '<div style="color:red;">'.$row['rules'].'</div>'; $moderators = explode(" ", $row['moderators']); $moderators = implode(",", $moderators); echo '<div class="pbw_bbsBanzhu">版主:'.$moderators.'</div>'; echo '</td>'; echo '<td width="90"> </td>'; echo '<td width="120" align="center">'; echo $row['threads'].'/'.$row['posts']; echo '</td>'; echo '<td>'; $lastpost = explode(" ", $row['lastpost']); echo '<a href="/bbs/forum.php?mod=viewthread&tid='.$lastpost[0].'#lastpost">'.$lastpost[1].'</a> (<a href="/bbs/home.php?mod=space&username='.$lastpost[3].'" style="color:#369">'.$lastpost[3].'</a>)<br />'; echo date("Y-m-d H:i:s", $lastpost[2]); echo '</td>'; echo '</tr>'; echo '</table>'; } {/dede:php}
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!