Heim  >  Artikel  >  Backend-Entwicklung  >  帝国CMS 列表模板listvar支持程序代码

帝国CMS 列表模板listvar支持程序代码

ringa_lee
ringa_leeOriginal
2018-05-11 15:21:133059Durchsuche

1、增加模板时list.var模板需要勾选“使用程序代码”选项。如图:

2、直接添加PHP代码,不需要加

list.var模板范例:
例子1:如果信息没有设置标题图片就显示指定的图片。

1if(empty($r[titlepic]))
2{
3        $r[titlepic]='/images/img.gif';
4}
5 $listtemp=&#39;<li><a href="[!--titleurl--]"><img src="[!--titlepic--]">a>li>&#39;;

说明:$r[titlepic]为标题图片字段变量。$listtemp为模板内容变量。

例子2:如果信息是今天发布的就显示“NEW”图片标识。

1$newimg=&#39;&#39;;
2 if(time()-$r[newstime]<=1*24*3600)
3{
4        $newimg=&#39;<img src="NEW图片地址" border="0">&#39;;
5}
6 $listtemp=&#39;<li><a href="[!--titleurl--]">[!--title--]a> &#39;.$newimg.&#39;li>&#39;;

说明:$r[newstime]为发布时间字段变量。$listtemp为模板内容变量。

例子3:调用投稿用户的公司名称。

1$userr=$empire->fetch1("select company from {$dbtbpre}enewsmemberadd where userid=&#39;$r[userid]&#39; limit 1");
2 $listtemp=&#39;<li><a href="[!--titleurl--]">[!--title--]a><span>公司名称:&#39;.$userr[company].&#39;span>li>&#39;;

说明:$r[userid]为发布者用户ID字段变量。$listtemp为模板内容变量。

其他说明:
如果$listtemp引用模板内容是用单引号,那么里面使用单引号前面要加\,例如:$listtemp='9e101c6c6562f65a00ea9abf5be8a1b8';
相反如果引用模板内容是用双引号,那么里面使用双引号前面也要加\,例如:$listtemp="67354a9d7dfae5e58bb9c32d3d2b6888";
支持程序代码可以实现很多非常复杂的应用需求。

以上就介绍了帝国CMS  列表模板listvar支持程序代码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn