您可以使用add_rewrite_rule
连接到init
操作,而不是使用generate_rewrite_rules
过滤器(其中it gets a bit low-level).
但重写规则的实际问题是存在正则表达式。下面是它的样子:
function wtnerd_edition_specific_categories() {
add_rewrite_rule( \'(.+?)/channel/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]\', \'top\' );
add_rewrite_rule( \'(.+?)/channel/(.+?)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]\', \'top\' );
add_rewrite_rule( \'(.+?)/channel/(.+?)/page/?([0-9]{1,})/?$\', \'index.php?category_name=$matches[1]&channel=$matches[2]&paged=$matches[3]\', \'top\' );
add_rewrite_rule( \'(.+?)/channel/(.+?)/?$\', \'index.php?category_name=$matches[1]&channel=$matches[2]\', \'top\' );
add_rewrite_rule( \'(.+?)/section/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]\', \'top\' );
add_rewrite_rule( \'(.+?)/section/(.+?)/(feed|rdf|rss|rss2|atom)/?$\', \'index.php?category_name=$matches[1]&tag=$matches[2]&feed=$matches[3]\', \'top\' );
add_rewrite_rule( \'(.+?)/section/(.+?)/page/?([0-9]{1,})/?$\', \'index.php?category_name=$matches[1]&tag=$matches[2]&paged=$matches[3]\', \'top\' );
add_rewrite_rule( \'(.+?)/section/(.+?)/?$\', \'index.php?category_name=$matches[1]&tag=$matches[2]\', \'top\' );
}
add_action( \'init\', \'wtnerd_edition_specific_categories\' );
您还可以使用
rewrite_rules_array
过滤器挂钩。