WordPress多个具有相同自定义帖子类型的同一类别的模板 [英] Wordpress multiple template for same category with different custom post type
问题描述
我的Wordpress网站具有以下结构:
I have this structure for my Wordpress site :
- 自定义帖子类型1
- 类别a
- a-1项
- a-2项
- ...
- 类别(与CPT 1相同的类别)
- a-1项
- a-2项
- ...
我想根据当前帖子类型为类别"存档页面和单学期页面使用不同的模板.我该如何实现?
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?
换句话说,我希望这些URL各自具有自己的模板:
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/(与1相同,但CPT URL不同)
- http://www.example.com/custom-post-type-2/category-a/generic-single-term (与2相同,但CPT URL不同)
- 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)
谢谢!
推荐答案
您需要使用
taxonomy.php
模板文件(及其衍生版本)或category.php
模板文件(及其派生文件)(仅用于类别分类法).You need to use the
taxonomy.php
template file (and its derivatives) or thecategory.php
template file (and its derivatives) , ( which is is only for use with the Category taxonomy ) .如果您想要一些自定义分类法的存档索引,则可以使用
taxonomy- {taxonomy} .php
模板文件.因此,如果您创建了自定义分类法my-taxonomy
,则该分类法的存档索引将使用taxonomy-my-taxonomy.php
模板文件.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 thetaxonomy-my-taxonomy.php
template file.如果您想在自定义分类法中为某些术语创建归档索引,请使用
taxonomy- {taxonomy}-{term} .php
模板文件.因此,如果您有一个用于自定义分类法的术语my-term
,则该术语的存档索引将为taxonomy-my-taxonomy-my-term.php 代码>.
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 betaxonomy-my-taxonomy-my-term.php
.(注意:我认为最好用一个词来表示分类法和/或术语.)
(Note:a single word for name of taxonomy and or terms is better I Think.)
有关模板层次结构 CODEX页面和分类法特定的
此处 More info on the template hierarchy CODEX page and taxonomy specific Here
这篇关于WordPress多个具有相同自定义帖子类型的同一类别的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 类别a