帝国CMS最新文章的时间显示为红色

我们在浏览网页的时候,会发现有些博客主真的会吸引浏览者的眼球,他们把最新文章的发布时间设置为了红色,其他时间段的时间显示正常,这样设置有一个很大的好处,就是浏览者一眼就可以看出那一篇文章实在二十四小时之内发布的,是自己需要的最新文章,可以很好的增加网站粘性,但是我们也知道,帝国CMS或者其他的网站程序,调用文章时候显示的时间代码都是一个样子,很明显他们修改了程序代码,今天我们就来修改程序代码,实现这个24小时内发布的文章,发布时间显示为红色的功能

我们先来看首页模板的调用,需要在模板之中调用时间的地方添加如下代码

1
2
3
4
5
6
7
8
9
10
[e:loop={0,10,3,0}]
<?php
$color="";
if(date("Y-m-d",$bqr[newstime])==date("Y-m-d"))
{
$color="red";
}
?>
<li><FONT color=<?=$color?>><?=date('Y-m-d',$bqr[newstime])?></FONT> &nbsp;&nbsp; <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a></li>
[/e:loop]

大家也可是使用一下下面的代码

1
2
3
4
5
6
7
8
9
10
[e:loop={0,10,3,0}]
<?php
$color="";
if(date("Y-m-d",$bqr[newstime])==date("Y-m-d"))
{
$color="red";
}
?>
<li><font color=<?=$color?>><?=date('Y-m-d',$bqr[newstime])?></font> &nbsp;&nbsp; <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a></li>
[/e:loop]

并没有做任何的修改,占一个篇幅,不过把大写的FONT改成了小写font不知道会不会影响代码使用。然后是列表页调用,需要使用如下代码

1
2
3
4
5
6
$newimg='[!--newstime--]';
if(time()-$r[newstime]<=1*24*3600)
{
$newimg='<fontcolor=red>[!--newstime--]</font>';
}
$listtemp='<li><span class=date>'.$newimg.'</span> <a href="[!--titleurl--]" target=_blank>[!--title--]</a> </li>';

这个代码比较悲催,为什么呢,需要添加到栏目列表页或者标签页的列表内容模板中,而且需要先勾选开启列表内容模板右上角的使用程序代码的复选框,更为关键的是,自己列表循环的代码样式,需要放在

1
$listtemp='列表循环样式'

里面来替换,也就是上面代码的最后一句中

1
$listtemp='<li><span class=date>'.$newimg.'</span> <a href="[!--titleurl--]" target=_blank>[!--title--]</a> </li>';

的列表循环样式,其实是

1
<li><span class=date>'.$newimg.'</span> <a href="[!--titleurl--]" target=_blank>[!--title--]</a> </li>

别嫌弃哥啰嗦,哥是为了让文章显得高大上,上面强调的代码样式替换,经历过的朋友自然会懂。也有朋友说使用以下代码也可以

1
2
3
4
5
6
7
8
9
10
<?php
$timedays=strtotime(date("Y-m-d",time()));//今天0点的时间点
$timedaye=$timedays+3600*24;//今天24点的时间点,两个值之间即为今天一天内的数据
$xinxi_sql=$empire->query('select id,title,titleurl from '.$dbtbpre.'ecms_news where newstime between '.$timedays.' and '.$timedaye.' order by newstime limit 10');
while($xinxi_row=$empire->fetch($xinxi_sql)){
?>
<li><a href="<?=$xinxi_row[titleurl]?>"><?=$xinxi_row[title]?></a></li>
<?
}
?>

或者使用最后的代码,注意看第四行sql查询的区别

1
2
3
4
5
6
7
8
9
10
<?php
$timedays=strtotime(date("Y-m-d",time()));//今天0点的时间点
$timedaye=$timedays+3600*24;//今天24点的时间点,两个值之间即为今天一天内的数据
$xinxi_sql=$empire->query('select id,title,titleurl from '.$dbtbpre.'ecms_news where newstime>='.$timedays.' and newstime<='.$timedaye.' order by newstime limit 10');
while($xinxi_row=$empire->fetch($xinxi_sql)){
?>
<li><a href="<?=$xinxi_row[titleurl]?>"><?=$xinxi_row[title]?></a></li>
<?
}
?>

反正是我不懂,不过我感觉前面的两种方法还是比较靠谱的,至于后面的方法,我没有测试,主要是感觉太啰嗦了。谢谢大家。