Wordpress显示新增文章的时间格式为“几分钟”前
程序员文章站
2022-06-10 20:45:24
...
有点像微博的样式,发布日期显示为“几秒前”,“几分钱”,“几小时前”的格式。
function timeago() { global $post; $date = $post->post_date; $time = get_post_time('G', true, $post); $time_diff = time() - $time; if ( $time_diff > 0 && $time_diff < 24*60*60 ) $display = sprintf( __('%s ago'), human_time_diff( $time ) ); else $display = date(get_option('date_format'), strtotime($date) ); return $display; } add_filter('the_time', 'timeago');