这应该可以:
add_action( \'init\', \'wpa12742_init\' );
function wpa12742_init(){
add_rewrite_rule( \'category/(.+?)/(\\d{4})/?$\', \'index.php?category_name=$matches[1]&year=$matches[2]\', \'top\' );
add_rewrite_rule( \'category/(.+?)/(\\d{4})/page/(\\d+)/?$\', \'index.php?category_name=$matches[1]&year=$matches[2]&paged=$matches[3]\', \'top\' );
}
再想一想,这还不够,因为你会被
redirect_canonical()
.
添加以下内容:
add_filter( \'term_link\', \'wpa12743_term_link\', 10, 3 );
function wpa12743_term_link( $link, $term, $taxonomy ){
if(\'category\' != $taxonomy && !preg_match( \'@^\\d{4}$@\', get_query_var(\'year\') ) )
return $link;
return trailingslashit( $link ) . get_query_var( \'year\' );
}