修改WordPress文章索引列表的日期格式

WordPress 默认的文章索引日期格式为“四位数字年汉字月”(如“2010年四月”)

看起来很不习惯,现在我们把它改成熟悉的“yyyy年mm月”格式,并在后面加上文章数(如“2010年04月 (2)”)

修改前后的效果如下面左右两图:

image image

找到文件wp-includes/general-template.php,自行备份后并打开

找到方法 function wp_get_archives($args = '')

image

找到方法中 if ( 'monthly' == $type ) 块中设置 $text 的代码

$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);

image

把这行代码修改为:

$text = sprintf(__('%1$s年%2$s月 (%3$d)'), $arcresult->year, zeroise(intval($arcresult->month), 2), $arcresult->posts);

image

保存后覆盖服务器文件即可。

原文地址:https://www.cnblogs.com/vengen/p/1702338.html