dede当天或24小时内发表文章日期显示红色
类别:建站知识   时间:03-06

真正的“当天”显示红色,实现代码:

[field:pubdate runphp='yes']if(date("Y-m-d",@me)==date("Y-m-d")){@me='<font color="#FF0000">'.GetDateTimeMK(@me).'</font>';}else{@me=GetDateTimeMK(@me);}[/field:pubdate]


在上面的代码中,我们使用了dedecms的标准时间函数(GetDateTimeMK(@me)),显示出来的时间是格式:2010-10-17 21:40:36,如果您想要其它格式,例如:年月日,那么实现代码如下:
[field:pubdate runphp='yes']if(date("Y-m-d",@me)==date("Y-m-d")){@me='<font color="#FF0000">'.MyDate('Y-m-d',@me).'</font>';}else{@me=MyDate('Y-m-d',@me);}[/field:pubdate]

再来看下24小时内发表的文章,显示红色的代码,我们直接用 pubdate - time() 做减法后判断情况输出结果。代码如下:
[field:pubdate runphp='yes']$nowTime = time();if($nowTime - (3600 * 24) < @me){@me='<font color="#FF0000">'.GetDateTimeMK(@me).'</font>';}else{@me=GetDateTimeMK(@me);}[/field:pubdate]

时间格式与当天的修改方法是一样的。不再赘述。(完)

智慧半岛,是一家专注于青岛网站建设青岛网站开发的青岛网络公司,Copyright ©2007-2019 Ebandao.Cn 版权所有 All Rights Reserved.(建议在1366x768以上的浏览器中访问)鲁ICP备08014496号

13153297890