剃头担子一头热 發表於 2020-1-30 21:59:51

帝国CMS列表页面分别调用年月日(显示个性时间日期)

<p>在帝国CMS中列表页个性时间显示的实现方式,首先我们要知道用什么方法来实现,这里我们使用PHP代码来做。</p>
<p>要在模板代码中使用PHP代码,就必须勾选此模板代码页面的-使用程序代码.位置就在添加模板页面的列表内容模板(list.var) (*)上边。</p>
<p>然后我们在list.var里边用PHP代码来实现我们的调用。</p>
<p>list.var使用PHP代码有几个规则</p>
<p>1、增加模板时list.var模板需要勾选&ldquo;使用程序代码&rdquo;选项。如图:</p>
<p><img src="https://img.jbzj.com/file_images/article/202001/20200130215816.jpg" alt="" /></p>
<p>2、直接添加PHP代码,不需要加&lt;?和?&gt;程序开始和结束标记。</p>
<p>3、字段值数组变量为$r,对应的字段变量为$r[字段名],如:标题字段变量就是$r。另外编号变量为$no</p>
<p>4、将最终模板内容赋给$listtemp变量。</p>
<p>例子2:如果信息是今天发布的就显示&ldquo;NEW&rdquo;图片标识。</p>
<blockquote>
<p>$newimg='';<br />
if(time()-$r&lt;=1*24*3600)<br />
{<br />
$newimg='&lt;img src=&quot;NEW图片地址&quot; border=&quot;0&quot;&gt;';<br />
}<br />
$listtemp='&lt;li&gt;&lt;a href=&quot;[!--titleurl--]&quot;&gt;[!--title--]&lt;/a&gt; '.$newimg.'&lt;/li&gt;';</p>
</blockquote>
<p>上边将了在list.var中使用PHP规则,下边继续看我们的日期怎么实现。</p>
<p>我们在list.var中先使用以下代码分别获取年、月、日等</p>
<blockquote>
<p>$newstime=$r;//获取信息发布时间<br />
$year=format_datetime($newstime,&quot;Y&quot;);//单独获取年<br />
$month=format_datetime($newstime,&quot;m&quot;);//单独获取月<br />
$day=format_datetime($newstime,&quot;d&quot;);//单独获取日</p>
</blockquote>
<p>然后在需要的地方添加</p>
<p>年:'.$year.'<br />
月:'.$month.'<br />
日:'.$day.'<br />
自己按需调用即可。</p>
<p>所以list.var中的完整代码就是</p>
<blockquote>
<p>$newstime=$r;//获取信息发布时间<br />
$year=format_datetime($newstime,&quot;Y&quot;);//单独获取年<br />
$month=format_datetime($newstime,&quot;M&quot;);//单独获取月<br />
$day=format_datetime($newstime,&quot;d&quot;);//单独获取日<br />
$listtemp='&lt;div class=&quot;new_li&quot;&gt;<br />
&lt;div id=&quot;xinwenDate&quot;&gt;&lt;p class=&quot;day&quot;&gt;'.$day.'&lt;/p&gt;&lt;p class=&quot;month&quot;&gt;'.$month.'&lt;/p&gt;&lt;p class=&quot;year&quot;&gt;'.$year.'年&lt;/p&gt;&lt;/div&gt;<br />
&lt;div id=&quot;xinwenList&quot;&gt;<br />
&lt;p class=&quot;xinwenTitle&quot;&gt;&lt;a href=&quot;[!--titleurl--]&quot;&gt;[!--title--]&lt;/a&gt;&lt;/p&gt;<br />
&lt;div class=&quot;xinwenText&quot;&gt;[!--smalltext--]&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;';</p>
</blockquote>
<p>好了这篇文章就介绍到这了</p>
頁: [1]
查看完整版本: 帝国CMS列表页面分别调用年月日(显示个性时间日期)