类别没有基于日期的存档。这个/category/[slug]/
页面已经是“档案”,因为它们在不同的页面上显示旧帖子。
可以通过添加page/2/
, page/3/
, ... 到URL。要添加这些链接的模板标记包括next_posts_link()
和previous_posts_link()
.
如果要将基于日期的图层添加到类别存档中,可以添加重写规则以匹配年份、可选月份和可选分页。
add_filter( \'category_rewrite_rules\', \'wpse8769_category_rewrite_rules\' );
function wpse8769_category_rewrite_rules( $category_rules )
{
global $wp_rewrite;
// This could be incorrect for fancy permastructs, only tested in simple situations
$category_permastruct = str_replace( $wp_rewrite->rewritecode, $wp_rewrite->rewritereplace, $wp_rewrite->get_category_permastruct() );
$category_permastruct = preg_replace( \'|^/+|\', \'\', $category_permastruct );
$category_extra_rules = array(
// Or split this up over different rewrite rules, if the regex is too complicated
// Feeds are left as an exercise for the reader
$category_permastruct . \'/([0-9]{4})(/([0-9]{1,2}))?(/page/([0-9]+))?/?$\' =>
\'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[4]&paged=$matches[6]\',
);
return $category_extra_rules + $category_rules;
}