所有方法均圍繞 pubdate 字段,通過模板標籤 [field:pubdate runphp='yes'] 嵌入 PHP 代碼判斷發布時間是否在指定範圍內(預設 3 天,即 3600 * 24 * 3 秒)。若需僅標記當天,將時間閾值改為 3600 * 24 即可。
注意: 輸出 HTML 時屬性值請使用單引號(如 <img src='new.gif' />),雙引號會導致模板解析錯誤。
[field:pubdate runphp='yes']
$a = "<font color=red>".strftime('%m-%d', @me)."</font>";
$b = strftime('%m-%d', @me);
$ntime = time();
$day3 = 3600 * 24 * 3;
if (($ntime - @me) < $day3) @me = $a;
else @me = $b;
[/field:pubdate]
[field:pubdate runphp='yes']
$aa = strftime('%m-%d', @me);
$ntime = time();
$tagtime = @me;
$day3 = 3600 * 24 * 3;
if ($tagtime > $ntime - $day3) @me = "<font color='red'>(new)</font>";
else @me = $aa;
[/field:pubdate]
[field:pubdate runphp='yes']
$aa = strftime('%m-%d', @me);
$ntime = time();
$tagtime = @me;
$day3 = 3600 * 24 * 3;
if ($tagtime > $ntime - $day3) @me = "<img src='new.gif' />".$aa;
else @me = $aa;
[/field:pubdate]
將上述代碼放入列表頁或首頁模板的日期顯示位置,即可自動為最新內容添加醒目標識,提升用戶體驗。