不同的定制帖子类型对应不同的soronomy.php 时间:2016-06-04 作者:Pete 我有taxonomy.php post\\u类型“posts”的模板文件,但我想使用另一种分类法。php,但只需将其用于/应用于自定义帖子类型。这是否有可能成为另一种分类法。仅针对特定自定义帖子类型的php文件? 2 个回复 SO网友:Mark Kaplun 我想说的是,如果post type A的分类法T与post type B的分类法T在逻辑上有足够的不同,以至于您需要不同的URL和显示等等,那么对于不同的post类型,最好有两种不同的分类法。为不同的内容使用相同的标签的目的是表明它们是相关的,而你说你实际上不希望它们是相关的 SO网友:thebigtine get_template_part() & get_post_type()我们可以通过组合get_template_part() 和get_post_type() 像这样:get_template_part( \'taxonomy\', get_post_type() ); 其工作原理是get_post_type() 将返回当前显示的帖子类型的名称,并将其传递给get_template_part(), 所以如果我们在一个岗位上,它会尝试加载taxonomy-post.php 并回退到taxonomy.php 如果taxonomy-post.php 不存在。如果我们在同一页上,taxonomy-page.php 和taxonomy.php. 如果我们使用自定义帖子类型,比如一本书,它将查找taxonomy-book.php 然后回到taxonomy.php.WP开发商文件get_template_part()get_post_type()多读些好书Understanding get_template_part by Konstantin Kovshenin 文章导航