帝国CMS列表页面list.var分别调用年月日,显示个性时间日期

2019-03-2616:25:36网站建设与开发Comments1,740 views字数 1259阅读模式
Excerpt

在帝国CMS中列表页个性时间显示的实现方式,首先我们要知道用什么方法来实现,这里我们使用PHP代码来做。

帝国CMS中列表页个性时间显示的实现方式,首先我们要知道用什么方法来实现,这里我们使用PHP代码来做。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

要在模板代码中使用PHP代码,就必须勾选此模板代码页面的-使用程序代码.位置就在添加模板页面的列表内容模板(list.var) (*)上边。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

然后我们在list.var里边用PHP代码来实现我们的调用。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

list.var使用PHP代码有几个规则文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

1、增加模板时list.var模板需要勾选“使用程序代码”选项。如图:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

帝国CMS列表页面list.var分别调用年月日,显示个性时间日期文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

2、直接添加PHP代码,不需要加<?和?>程序开始和结束标记。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

3、字段值数组变量为$r,对应的字段变量为$r[字段名],如:标题字段变量就是$r[title]。另外编号变量为$no文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

4、将最终模板内容赋给$listtemp变量。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

例子2:如果信息是今天发布的就显示“NEW”图片标识。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

$newimg='';
if(time()-$r[newstime]<=1*24*3600)
{
$newimg='<img src="NEW图片地址" border="0">';
}
$listtemp='<li><a href="[!--titleurl--]">[!--title--]</a> '.$newimg.'</li>';

上边将了在list.var中使用PHP规则,下边继续看我们的日期怎么实现。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

我们在list.var中先使用以下代码分别获取年、月、日等文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

$newstime=$r[newstime];//获取信息发布时间
$year=format_datetime($newstime,"Y");//单独获取年
$month=format_datetime($newstime,"m");//单独获取月
$day=format_datetime($newstime,"d");//单独获取日

然后在需要的地方添加文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

年:'.$year.'
月:'.$month.'
日:'.$day.'

自己按需调用即可。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

所以list.var中的完整代码就是文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html

$newstime=$r[newstime];//获取信息发布时间
$year=format_datetime($newstime,"Y");//单独获取年
$month=format_datetime($newstime,"M");//单独获取月
$day=format_datetime($newstime,"d");//单独获取日
$listtemp='<div class="new_li">
<div id="xinwenDate"><p class="day">'.$day.'</p><p class="month">'.$month.'</p><p class="year">'.$year.'年</p></div>
<div id="xinwenList">
<p class="xinwenTitle"><a href="[!--titleurl--]">[!--title--]</a></p>
<div class="xinwenText">[!--smalltext--]</div>
</div>
</div>';
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/10394.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/10394.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定