具有不同自定义帖子类型的同一类别的 Wordpress 多个模板 [英] Wordpress multiple template for same category with different custom post type

查看:29
本文介绍了具有不同自定义帖子类型的同一类别的 Wordpress 多个模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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 :

        1. http://www.example.com/custom-post-type-1/category-a/
        2. http://www.example.com/custom-post-type-1/category-a/generic-single-term
        3. http://www.example.com/custom-post-type-2/category-a/(与1相同但CPT URL不同)
        4. http://www.example.com/custom-post-type-2/category-a/generic-single-term(与2相同但CPT URL不同)
        1. http://www.example.com/custom-post-type-1/category-a/
        2. http://www.example.com/custom-post-type-1/category-a/generic-single-term
        3. http://www.example.com/custom-post-type-2/category-a/ (same as 1 but different CPT URL)
        4. 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 the category.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 the taxonomy-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 be taxonomy-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆