很多朋友希望網站的最新發布文章能夠突出顯示,這時就可以通過將最新文章的時間顏色進行凸顯,以便進行區分,本教程就是教大家如何將最新發布的文章的發布時間紅色顯示,適用于DEDECMS5.7、5.6版本。真正的“當天”顯示紅色,實現代碼如下:
-
[field:pubdaterunphp='yes']
-
if(date("Y-m-d",@me)==date("Y-m-d")){
-
@me='<fontcolor="#FF0000">'.GetDateTimeMK(@me).'</font>';
-
}
-
else{
-
@me=GetDateTimeMK(@me);
-
}
-
[/field:pubdate]
在上面的代碼中,我們使用了dedecms的標準時間函數(GetDateTimeMK(@me)),顯示出來的時間是格式:2010-10-17 21:40:36,如果您想要其它格式,例如:年月日,那么實現代碼如下:
-
[field:pubdaterunphp='yes']
-
if(date("Y-m-d",@me)==date("Y-m-d")){
-
@me='<fontcolor="#FF0000">'.MyDate('Y-m-d',@me).'</font>';
-
}else{
-
@me=MyDate('Y-m-d',@me);
-
}
-
[/field:pubdate]
再來看下24小時內發表的文章,顯示紅色的代碼,我們直接用 pubdate - time() 做減法后判斷情況輸出結果。
代碼如下:
-
[field:pubdaterunphp='yes']
-
$nowTime=time();
-
if($nowTime-(3600*24)<@me){
-
@me='<fontcolor="#FF0000">'.GetDateTimeMK(@me).'</font>';
-
}else{
-
@me=GetDateTimeMK(@me);
-
}
-
[/field:pubdate]
時間格式與當天的修改方法是一樣的。不再贅述。(完)