问题
I have this structure for my Wordpress site :
- Custom post type 1
- Category a
- Term a-1
- Term a-2
- ...
- Category a
- Custom post type 2
- Category a (same category than CPT 1)
- Term a-1
- Term a-2
- ...
- Category a (same category than CPT 1)
I would like to have different template for "Category a" archive page and single term page depending of current post type. How can I achieve this?
In other words, I want these URLs each have their own template :
- http://www.example.com/custom-post-type-1/category-a/
- http://www.example.com/custom-post-type-1/category-a/generic-single-term
- http://www.example.com/custom-post-type-2/category-a/ (same as 1 but different CPT URL)
- http://www.example.com/custom-post-type-2/category-a/generic-single-term (same as 2 but different CPT URL)
Thank you!
回答1:
You need to use the taxonomy.php
template file (and its derivatives) or the category.php
template file (and its derivatives) , ( which is is only for use with the Category taxonomy ) .
If you want an archive index for some custom taxonomy, you would use taxonomy-{taxonomy}.php
template file. So, if you have created a custom taxonomy, my-taxonomy
, the archive index for this taxonomy would use the taxonomy-my-taxonomy.php
template file.
If you want an archive index for some terms inside your custom taxonomy, you use taxonomy-{taxonomy}-{term}.php
template file. So, if you've got a term, my-term
, for your custom taxonomy, the archive index for this term would be taxonomy-my-taxonomy-my-term.php
.
(Note:a single word for name of taxonomy and or terms is better I Think.)
More info on the template hierarchy CODEX page and taxonomy specific Here
来源:https://stackoverflow.com/questions/32875274/wordpress-multiple-template-for-same-category-with-different-custom-post-type