我使用此代码获取特定类别的存档:
function extend_date_archives_add_rewrite_rules($wp_rewrite){
$rules = array();
$structures = array(
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(),
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(),
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(),
);
foreach( $structures as $s ){
$rules += $wp_rewrite->generate_rewrite_rules($s);
}
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_action(\'generate_rewrite_rules\', \'extend_date_archives_add_rewrite_rules\');
它工作得很好,我得到了一个URL,如:example。com/category\\u base/category\\u name/date/YYYY/MM
问题是我想要一个没有category\\u base的URL:example。com/category\\u name/date/YYYY/MM
如果我使用插件删除de“category\\u base”(如WP no category base) 或者简单地使用“str\\u replace”删除“category\\u base”,我在所有页面和单个页面中都会得到一个404错误页面。
我能做什么?
谢谢
Added notes:
如果我使用:
function extend_date_archives_flush_rewrite_rules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action(\'init\', \'extend_date_archives_flush_rewrite_rules\');
function extend_date_archives_add_rewrite_rules($wp_rewrite){
$rules = array();
$structures = array(
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(),
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(),
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(),
);
foreach( $structures as $s ){
$rules += $wp_rewrite->generate_rewrite_rules($s);
}
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_action(\'generate_rewrite_rules\', \'extend_date_archives_add_rewrite_rules\');
示例。com/category\\u name/YYYY工作正常,但single和pages转到404页。但如果我只使用:
function extend_date_archives_add_rewrite_rules($wp_rewrite){
$rules = array();
$structures = array(
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(),
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(),
$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(),
);
foreach( $structures as $s ){
$rules += $wp_rewrite->generate_rewrite_rules($s);
}
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_action(\'generate_rewrite_rules\', \'extend_date_archives_add_rewrite_rules\');
然后,所有的单页和页都可以正常工作,但示例除外。com/category\\U name/YYYY转到404。有什么想法吗?我刷新permalinks,然后继续处理问题:(