我使用它来启用自定义帖子类型的年度和月度存档。只需将此代码输入到functions.php
文件
这将在Rules array. NB-Wordpress使用规则数组存储重写规则。
<?php
function wpse22992_custom_post_rewrite( $rewrite_rules ) {
$cpslug = \'contest_recipe\'; // custom post type slug
// Rule to display monthly archive -> contest_recipe/2012/08/
$year_archive = array( $cpslug . \'/([0-9]{4})/([0-9]{1,2})/?$\' => \'index.php?year=$matches[1]&monthnum=$matches[2]&post_type=\' . $cpslug );
// Rule to display yearly archive -> contest_recipe/2012/
$month_archive = array( $cpslug . \'/([0-9]{4})/?$\' => \'index.php?year=$matches[1]&post_type=\' . $cpslug );
$rewrite_rules = $year_archive + $month_archive + $rewrite_rules;
return $rewrite_rules;
}
add_filter(\'rewrite_rules_array\', \'wpse22992_custom_post_rewrite\');
?>
资源-Wordpress筛选器-
rewrite_rules_array
Rewrite Rules Inspector
(有助于生成更多组合)