2014-03-31 16 views
0

在Wordpress中,我爲名爲「People」的CPT創建了一個名爲「Cities」的分類標準。我想在single.php文件的模板中顯示爲某個人選擇的所有分類標記。Wordpress:只顯示選定的分類標記

只顯示選定元素的代碼是什麼?

我用下面的代碼中的單people.php:

<?php 
$taxonomy = 'cities'; 
$terms = get_terms($taxonomy); 

if ($terms && !is_wp_error($terms)) : 
?> 
    <ul> 
    <?php foreach ($terms as $term) { ?> 
    <li><a href="<?php echo wp_get_post_terms($term -> slug, $taxonomy); ?>"><?php echo $term -> name; ?></a></li> 
    <?php 
    } ?> 
    </ul> 
<?php endif; ?>  

我只希望不帶鏈接選定的分類標籤。

+0

旁邊的鏈接,什麼是分類名稱錯? –

回答

0

我知道你想顯示所有術語選擇單個一個分類

您需要使用的功能wp_get_post_terms()這樣的:

$taxonomy = 'cities'; 
$post_terms = wp_get_post_terms($post->ID, $taxonomy, array("fields" => "names")); 

foreach ($post_terms as $term) { 
    echo $term; 
} 

這將打印城市當前有關的所有名稱。現在你必須調整這個代碼到你的頁面,如果你不想要鏈接,只是不要使用<a>標籤...

相關問題