详情页

帝国cms 列表内容模板(list.var) 调用数据库

时间:2023年11月07日

编辑:佚名

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

2、直接添加PHP代码,不需要加<?和?>程序开始和结束标记。
3、字段值数组变量为$r,对应的字段变量为$r[字段名],如:标题字段变量就是$r[title]。另外编号变量为$no
4、将最终模板内容赋给$listtemp变量。
list.var模板范例:
例子1:如果信息没有设置标题图片就显示指定的图片。
 if(empty($r[titlepic]))
 {
         $r[titlepic]='/images/img.gif';
 }
 $listtemp='<li><a href="[!--titleurl--]"><img src="[!--titlepic--]"></a></li>';
说明:$r[titlepic]为标题图片字段变量。$listtemp为模板内容变量。
例子2:如果信息是今天发布的就显示“NEW”图片标识。
 $newimg='';
 if(time()-$r[newstime]<=1*24*3600)
 {
         $newimg='<img src="NEW图片地址" border="0">';
 }
 $listtemp='<li><a href="[!--titleurl--]">[!--title--]</a> '.$newimg.'</li>';
说明:$r[newstime]为发布时间字段变量。$listtemp为模板内容变量。
调用投稿用户的公司名称。
 $userr=$empire->fetch1("select company from {$dbtbpre}enewsmemberadd where userid='$r[userid]' limit 1");
 $listtemp='<li><a href="[!--titleurl--]">[!--title--]</a> <span>公司名称:'.$userr[company].'</span></li>';
说明:$r[userid]为发布者用户ID字段变量。$listtemp为模板内容变量。
调用新闻副表中的newstext字段为例:
$fr=$empire->fetch1("select newstext from {$dbtbpre}ecms_news_data_{$r[stb]} where id='$r[id]'");
$listtemp='<a href="[!--titleurl--]">[!--title--]</a> <br>副表内容字段:'.$fr[newstext].'<br><br>';
其他说明: 如果$listtemp引用模板内容是用单引号,那么里面使用单引号前面要加\,例如:$listtemp=''; 相反如果引用模板内容是用双引号,那么里面使用双引号前面也要加\,例如:$listtemp="";
 
相关文章
猜你需要