WordPress时间格式改为“XX天前”
wordpress 默认的时间格式是具体时间,想要改成多少天前的样式。可以使用以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 | 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'); |
调用方法
1 | <?php the_time();?> |