/extend/function.php 最下方新增以下代碼,
if (!function_exists('diy_format_time')) {
function diy_format_time($date) {
$timeDifference = getTime() - $date;
$timeUnits = [
['label' => '年前', 'seconds' => 60 * 60 * 24 * 365],
['label' => '月前', 'seconds' => 60 * 60 * 24 * 30],
['label' => '天前', 'seconds' => 60 * 60 * 24],
['label' => '小時前', 'seconds' => 60 * 60],
['label' => '分鐘前', 'seconds' => 60]
];
foreach ($timeUnits as $unit) {
if ($timeDifference >= $unit['seconds']) {
$count = floor($timeDifference / $unit['seconds']);
return $count . $unit['label'];
}
}
return '剛剛';
}
}
然后再模板里面把時間標簽改成以下的
{$field.add_time|diy_format_time=###} 發(fā)布時間
{$field.update_time|diy_format_time=###} 更新時間
邏輯如下
1分鐘之內的 顯示剛剛,超過1分鐘的顯示分鐘數前,超過60分鐘的顯示 1個小時前,以此類推