百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 实用IT技术 » 正文

【Wordpress相关】WordPress 技巧:如何把时间显示成"xxx前"格式

发布时间:2020-09-17

作品分类:Wordpress相关  时间  格式  显示  格式  技巧  时间  显示  WordPress

WordPress 技巧:如何把时间显示成“xxx前”格式,

在微博中,时间的格式都是显示成:20秒前,1小时前,3天前这样的格式,其实 WordPress 也有一个函数可以把时间显示成这样的格式,这个函数就是:human_time_diff,它有两个参数,一个是 $from,一个是 $to,就是比较的两个时间戳。

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>

比如要日志的发表时间要改成:


<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>

而留言改成:


<?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?>

本站推荐使用的主机:,国外主机建议使用

Top