I’m now using wordpress 4.2, and developing themes on it for my own site.
I defined many custom post types in my theme, and I’m now finding a way to make some archive pages for them.
For example, I have a post_type called shop
, and have a taxonomy named region
assigned to it.
I to created a template file: category-region.php
Then I visit the permalink of this template: http://example.com/category/region/
, this template was matched, and init the query with all assigned shops, then display them.
But now I want to make a page with all posts of shop, no matter which region they are assigned.
How should I name the template file and what about the permalink?
I checked for the template hierarchy and have found the below diagram.
https://developer.wordpress.org/themes/basics/template-hierarchy/
It seems archive-$post_type.php
is what I wanted.
But what about the permalink that is pointing to this template?
The
rewrite
parameter in the arguments you pass toregister_post_type
determines the permalink for your custom post type archive.https://codex.wordpress.org/Function_Reference/register_post_type
Looking at the example in the documentation:
You can see that the rewrite slug for the book CPT is
book
, so the URL to the book archive would beexample.com/book/
.In your case, if you set your rewrite slug to
shop
(or if you didn’t set a rewrite slug, in which case it would default to your CPT slug), the URL that would correspond to yourarchive-shop.php
template would beexample.com/shop/
.Note that this assumes you are using permalinks, if you are not using permalinks the shop post type archive is located at
example.com/?post_type=shop
. If you are using permalink, make sure you refresh them after setting up your CPT by visiting theSettings > Permalinks
page.