有時候會碰到特殊的需求,比如調(diào)用文檔的發(fā)布時間,想要顯示幾天前、幾分鐘前、幾秒前的效果,這時候需要對程序二次改進來完成。
實現(xiàn)效果:
1:打開 /include/extend.func.php 在最下面加入以下代碼
/** * 麥站時間美化 * * @access public * @param string $time 時間戳 * @return string */ if(!function_exists('tranTime')) { function tranTime($time) { $rtime = date("m-d H:i",$time); $htime = date("H:i",$time); $etime = time() - $time; if ($etime < 1) return '剛剛'; $interval = array ( 12 * 30 * 24 * 60 * 60 => ' 年 前', 30 * 24 * 60 * 60 => ' 個 月 前', 7 * 24 * 60 * 60 => ' 周 前', 24 * 60 * 60 => ' 天 前', 60 * 60 => ' 小 時 前', 60 => ' 分 鐘 前', 1 => ' 秒 前' ); foreach($interval as $secs => $str) { $d = $etime / $secs; if($d >= 1) { $r = round($d); return $r . $str; } }; } } |
2:調(diào)用標簽寫法
首頁/列表頁
[field:pubdate function="tranTime(@me)"/]
內(nèi)容頁
{dede:field.pubdate function="tranTime(@me)"/}
如果你的時間格式是 2018-10-10 這種正常時間,那要這樣寫調(diào)用標簽
[field:pubdate function="tranTime(GetMkTime(@me))"/]
{dede:field.pubdate function="tranTime(GetMkTime(@me))"/}