无法添加到takien的帖子中,因此以下是我最后不得不做的事情:
functions.php
add_action(\'init\', \'my_year_archive_rewrites\');
function my_year_archive_rewrites() {
add_rewrite_rule(\'resource/news/([0-9]{4})/page/?([0-9]{1,})/?\', \'index.php?post_type=news&year=$matches[1]&paged=$matches[2]\', \'top\');
add_rewrite_rule(\'resource/news/([0-9]{4})/?\', \'index.php?post_type=news&year=$matches[1]\', \'top\');
}
add_filter(\'getarchives_where\', \'my_custom_post_type_archive_where\', 10, 2);
function my_custom_post_type_archive_where($where,$args){
$post_type = isset($args[\'post_type\']) ? $args[\'post_type\'] : \'post\';
return "WHERE post_type = \'$post_type\' AND post_status = \'publish\'";
}
add_filter(\'year_link\', \'my_year_link\');
function my_year_link($link) {
global $wp_rewrite;
if(true) { // however you determine what archive you want
$link = str_replace($wp_rewrite->front, \'/resource/news/\', $link);
}
return $link;
}
Calling wp_get_archives()
wp_get_archives(array(\'post_type\'=>\'news\', \'type\'=>\'yearly\'));