时间:2014-01-26所属栏目: WordPress教程 来源: 热度:
WordPress 默认的日记时刻函数 <?php the_time() ?> 表现出的时刻结果为“年代日时分秒”的数字分列,如 2013年2月27日 等多种方法。
怎样变动wordpress时刻表现方法,如 facebook 和 twitter 那样表现文章建设离此刻的时刻,好比 “2天前” “5分钟前”。除了修改 the_time() 的表现方法外,我们还可以通过 WordPress 的 human_time_diff() 函数来实现这个成果。
起首建设一个函数到functions中,复制下面的代码到 functions.php 中:
// Changing time ago
function time_ago( $type = 'post' ) {
$d = 'comment' == $type ? 'get_comment_time' : 'get_post_time';
return human_time_diff($d('U'), current_time('timestamp')) . "" . __('前');
}
然后你就可以在主题中挪用这个函数了:
<?php echo time_ago(); ?>
本网站首页表现出的时刻就是用这个方法调取的,安心行使吧!
另一种修改 WordPress 时刻表现为 几天前