2014-12-29 156 views
0

我有一個自定義帖子類型稱爲recipe和自定義分類標準爲cuisinerecipe_type顯示自定義帖子類型分類術語旁邊帖子在Wordpress

我要顯示的頁面與分類的相關術語10個食譜清單屬於:

我有下面的代碼顯示了食譜,但不是分類術語:

<?php 
query_posts(array( 
    'post_type' => 'recipe', 

    'showposts' => 10 
)); 
?> 
<?php while (have_posts()) : the_post(); ?> 
    <li> 
    <?php the_title(); ?> 
    <?php $terms = wp_get_post_terms($query->post->ID, array('cuisine', 'recipe_type')); ?> 

    <?php foreach ($terms as $term) : ?> 
    <p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p> 
    <?php endforeach; ?> 

    </li> 


<?php endwhile;?> 
+0

的分類項是'$查詢 - > POS t-> ID'甚至可以帶回任何東西?我不認爲這是基於您粘貼的代碼的有效變量。無論哪種方式,逐步調試將非常有用。 – Nic

回答

0

以下代碼工作,以顯示與自定義後類型

<?php 
query_posts(array( 
'post_type' => 'recipe', 

'showposts' => 10 
)); 
?> 

<?php while (have_posts()) : the_post(); ?> 
<li> 
<?php the_title(); ?> 
<?php $terms = get_the_terms($post->ID , 'recipe_type'); ?> 

<?php foreach ($terms as $term) : ?> 
<p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p> 
<?php endforeach; ?> 

</li> 
相關問題