函数为:
function timeago($posttime) {
$posttime = strtotime($posttime);
$thetime = time() - $posttime;
if ($thetime < 1) return '剛剛';
$interval = array(
12 * 30 * 24 * 60 * 60 => ' 年前 (' . date('Y-m-d', $posttime) . ')',
30 * 24 * 60 * 60 => ' 个月前 (' . date('m-d', $posttime) . ')',
7 * 24 * 60 * 60 => ' 周前 (' . date('m-d', $posttime) . ')',
24 * 60 * 60 => ' 天前',
60 * 60 => ' 小時前',
60 => ' 分鐘前',
1 => ' 秒前'
);
foreach ($interval as $secs => $strs) {
$i = $thetime / $secs;
if ($i >= 1) {
$round = round($i);
return $round . $strs;
}
};
}
需要的地方添加以下代码就OK了:
<div title="<?php the_time('Y年n月j日');?>" class="item-post-date">
<?php echo '發布於 '.timeago(get_gmt_from_date(get_the_time('Y-m-d G:i:s'))); ?>
</div>
评论区
发表新的留言
您可以留言提出您的疑问或建议。
您的留言得到回复时,会通过您填写的邮箱提醒您。