最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Possible for Category Base and Custom post Type to share the same slugpermalink?

programmeradmin0浏览0评论

Rebuilding an author/writer website in WordPress.

I have a custom post type of books. Working OK.

I'd also like my category base to be books. Not working as yet.

So a book URL would be like:

And a category URL would be:

How can I achieve this?

My workaround is a category URL like this (working using Category Base = books/category):

Would prefer to add code in functions.php or .htaccess than use a plugin.

Thanks

Rebuilding an author/writer website in WordPress.

I have a custom post type of books. Working OK.

I'd also like my category base to be books. Not working as yet.

So a book URL would be like:

https://www.authorname/books/title

And a category URL would be:

https://www.authorname/books/fiction

How can I achieve this?

My workaround is a category URL like this (working using Category Base = books/category):

https://www.authorname/books/category/fiction

Would prefer to add code in functions.php or .htaccess than use a plugin.

Thanks

Share Improve this question edited Sep 30, 2019 at 10:55 Matt Sephton asked Sep 30, 2019 at 10:39 Matt SephtonMatt Sephton 1772 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

No, it's not safe to use the /books/ URL for both a category base and custom post type base. WordPress uses the URLs to determine what type of content to serve. If you've set up 2 different types of content at the same URL, it won't have any way to know which you're requesting, and if you end up with a book slug that's the same as a category slug, you'll really have conflicts.

To keep the URL types segregated but still logical, you could use URLS such as

CPT: example/book/title-of-a-single-book

Category: example/books/category-name

Or, perhaps something like

CPT: example/books/title-of-a-single-book

Category: example/book-categories/category-name

Or, continue using your workaround, example/books/category/category-name, and they will all appear to be under "books."

发布评论

评论列表(0)

  1. 暂无评论