更新:已经增加了适合最新版 WordPress 的修改方法!请看文章最后。
俺在自行修改主题时发现,存档列表(archive)总是以 September 2006 这样的格式显示的。俺想把它改成 2006-09 这样的格式,但是不受后台设置里面日期格式的控制,查看帮助文档 wp_get_archives 语句似乎也不支持设置日期的格式,去 Wordpress 中文论坛问过之后得知这里确实不能通过设置或者模板更改,得去改源代码了。
搜索了一下源代码,不太费功夫就找到了,在 wp-includes/template-functions-general.php 文件里,get_archives 函数中,把:
$text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
改成
$text = sprintf('%d-%s', $arcresult->year, zeroise($arcresult->month,2));
就一切 OK 啦~ 还好俺还记得一点点大学的时候学的 C 语言…… ^^b
2008-5-26 更新:WordPress 新版(好像是2.5以后?)这个需要修改的文件变了,以下是新的修改方法。
打开文件 wp-includes/general-template.php,找到
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
改成
$text = sprintf(__('%1$d-%2$s'), $arcresult->year, zeroise($arcresult->month,2));
就行了!
