如果其他人正在寻找它,这里有一个 Matthew 答案的变体(完美地工作)来实现这一点:
博客存档: /blog/
博客类别: /blog/category-name/
博文: /blog/category-name/post-name/
add_action( 'generate_rewrite_rules', 'add_blog_rewrites' ); function add_blog_rewrites( $wp_rewrite ) { $wp_rewrite->rules = array( 'blog/([^/]+)/?$' => 'index.php?taxonomy=category&term=$matches[1]', 'blog/([^/]+)/page/([0-9]+)/?$' => 'index.php?taxonomy=category&term=$matches[1]&paged=$matches[2]', 'blog/[^/]+/([^/0-9]+)/?$' => 'index.php?name=$matches[1]', 'blog/[^/]+/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', 'blog/[^/]+/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'blog/[^/]+/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?name=$matches[1]&tb=1', 'blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/[^/]+/page/?([0-9]{1,})/?$' => 'index.php?name=$matches[1]&paged=$matches[2]', 'blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?name=$matches[1]&cpage=$matches[2]', 'blog/[^/]+/([^/]+)/[^/]+(/[0-9]+)?/?$' => 'index.php?name=$matches[1]&page=$matches[2]', 'blog/[^/]+/[^/]+/([^/0-9]+)/?$' => 'index.php?attachment=$matches[1]', 'blog/[^/]+/[^/]+/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'blog/[^/]+/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/[^/]+/([^/])+/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]' ) + $wp_rewrite->rules; }
和 /%category%/%postname%/
对于永久链接结构和类别链接:
function filter_category_link($permalink, $term) { if($term->taxonomy !== 'category') { return $permalink; } return 'blog' . str_replace('category/', '', $permalink); } add_filter('pre_term_link', 'filter_category_link', 10, 2);
原文链接:https://www.wordpresshy.com/390579
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END