我想为每个自定义的post-type分类术语做一个不同的single.php文件?

时间:2014-10-07 08:08:57

标签: php wordpress

我有一个自定义的后期“属性” - 然后我有自定义的后期类型分类:“open-homes”“features” - 我已经对不同的分类术语有不同的看法(例如,taxonomy-property-category-open-homes.php ) - 我希望“open-homes”单一视图“features”不同 - 我想通过为每个自定义后期类型分类法提供不同的single.php文件来实现此目的 - 我想要像 single-property-open-homes.php

这样的东西

我想这样做是因为我的帖子在两个分类中分配一个开放的家庭和特征,所以,我想要对每个分类法的不同观点。

我尝试过使用这个,但是这样所有的61分类都采用了这种布局。

<?php
    $terms = wp_get_post_terms( $post->ID,'property-category' );
    foreach($terms as $term)
    {

      $a=$term->term_id;
    }
       if($a == 61)
       {
       get_template_part( 'looptest', get_post_format());
        }
       else{
       get_template_part( 'listing', 'single' );
       }

       ?>

但这不起作用,因为。 post在term id 61和18中分配,但我想当term id为61时,它的单个视图不同。

请帮助完成这项工作。

谢谢&amp;问候。

1 个答案:

答案 0 :(得分:0)

您可以通过使用Wordpress模板层次结构来完成此操作(请参阅下面链接中的图表)。

http://codex.wordpress.org/Template_Hierarchy

在您的情况下,您会使用“single-open-homes.php”和“single-features.php”

希望这有帮助。