以下代码加入function.php文件中,重启php-fpm,刷新页面即可看到效果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /** * WordPress 实现文章和评论日期时间格式为几分钟之前几小时之前 */ function Bing_filter_time(){ global $post ; $to = time(); $from = get_the_time('U') ; $diff = (int) abs($to - $from); if ($diff <= 3600) { $mins = round($diff / 60); if ($mins <= 1) { $mins = 1; } $time = sprintf(_n('%s 分钟', '%s 分钟', $mins), $mins) . __( '前' , 'Bing' ); } else if (($diff <= 86400) && ($diff > 3600)) { $hours = round($diff / 3600); if ($hours <= 1) { $hours = 1; } $time = sprintf(_n('%s 小时', '%s 小时', $hours), $hours) . __( '前' , 'Bing' ); } elseif ($diff >= 86400) { $days = round($diff / 86400); if ($days <= 1) { $days = 1; $time = sprintf(_n('%s 天', '%s 天', $days), $days) . __( '前' , 'Bing' ); } elseif( $days > 29){ $time = get_the_time(get_option('date_format')); } else{ $time = sprintf(_n('%s 天', '%s 天', $days), $days) . __( '前' , 'Bing' ); } } return $time; } add_filter('the_time','Bing_filter_time'); |
原文链接:https://xiaohost.com/4198.html,转载请注明出处。
评论0