URL 在 WordPress 中显示不必要的 post 类型
URL showing unnecessary post types in WordPress
我的网站,暂且称它为 example.com,有几个 Post 类型:
- Post (the default post type) with the slug 'blog'
- Cases with the slug 'cases'
- Klanten with the slug 'klanten' (Dutch word for clients)
当我进入博客页面时,url 显示如下:
example.com/blog/
然后当我导航到博客 post 时,它显示如下:
example.com/blog/blog-title/
这个也不错
但是现在问题来了。当我进入案例页面时,URL 显示如下:
example.com/cases/
这很好,但是当我select一个案例时,URL显示如下:
example.com/blog/cases/case-title/
当然,我希望这个 URL 是:
example.com/cases/case-title/
尝试使用附加参数 'with_front' => false
调用 register_post_type() 参数 'rewrite'
From Codex documentation:
'with_front' => bool Should the permalink structure be prepended with
the front base. (example: if your permalink structure is /blog/, then
your links will be: false->/news/, true->/blog/news/). Defaults to
true
$args = array(
/*other args*/
'rewrite' => array('slug' => 'cases', 'with_front' => false),
/*other args*/
);
register_post_type( 'cases', $args );
我的网站,暂且称它为 example.com,有几个 Post 类型:
- Post (the default post type) with the slug 'blog'
- Cases with the slug 'cases'
- Klanten with the slug 'klanten' (Dutch word for clients)
当我进入博客页面时,url 显示如下:
example.com/blog/
然后当我导航到博客 post 时,它显示如下:
example.com/blog/blog-title/
这个也不错
但是现在问题来了。当我进入案例页面时,URL 显示如下:
example.com/cases/
这很好,但是当我select一个案例时,URL显示如下:
example.com/blog/cases/case-title/
当然,我希望这个 URL 是:
example.com/cases/case-title/
尝试使用附加参数 'with_front' => false
调用 register_post_type() 参数 'rewrite'From Codex documentation: 'with_front' => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true
$args = array(
/*other args*/
'rewrite' => array('slug' => 'cases', 'with_front' => false),
/*other args*/
);
register_post_type( 'cases', $args );