具有不同自定义帖子类型的同一类别的 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 学期
- ...
- A 类(与 CPT 1 相同的类别)
- 第 a-1 学期
- 第 a-2 学期
- ...
我想根据当前的帖子类型为A 类"存档页面和单术语页面使用不同的模板.我怎样才能做到这一点?
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/(与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.)
More info on the template hierarchy CODEX page and taxonomy specific Here
这篇关于具有不同自定义帖子类型的同一类别的 Wordpress 多个模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- A 类