我有自定义的重写规则,以便帖子页面URL可以/blog/
所有帖子都有URL结构/blog/post-title-here/
, 这很好,但是我在/blog/
页面分页的结构如下/blog/page/2/
-- 我看到了many 有关StackOverflow的主题和问题,但似乎所有回答都是针对类别的/blog/cat-name/page/2/
在我需要的地方/blog/page/2/
下面是我要附加的重写函数/blog/
发布URL:
add_action( \'generate_rewrite_rules\', \'site_add_blog_rewrites\' );
function site_add_blog_rewrites( $wp_rewrite ) {
$wp_rewrite->rules = array(
\'blog/([^/]+)/?$\' => \'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/([^/]+)/?([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/[^/]+/([^/]+)/?$\' => \'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;
}
然后我使用以下方法转换后permalinks:
function site_filter_post_link($permalink, $post) {
if ($post->post_type != \'post\') {
return $permalink;
}
return \'blog\'.$permalink;
}
add_filter(\'pre_post_link\', \'site_filter_post_link\', 10, 2);
我是否缺少允许URL结构的正确重写
/blog/page/2/
或者这不可能,因为WP正在思考
/page/
在这个结构中应该是一个帖子吗?任何帮助都将不胜感激!
NOTE: 我cannot 有我的permalinks结构/%category%/%postname%/
. permalinks必须留在/%postname%/