2015-05-21 48 views
0

我有這個代碼的偉大工程,以顯示子類別名稱和我選擇一個特定的父類的鏈接:的WordPress:顯示子目錄名稱不帶鏈接

<?php 
$taxonomy = 'category'; 

// get the term IDs assigned to post. 
$post_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); 
// separator between links 
$categories = get_the_category(); 
$parentid = '6'; 

if (!empty($post_terms) && !is_wp_error($post_terms)) { 

$term_ids = implode(',' , $post_terms); 
$terms = strtr(wp_list_categories('title_li=&style=none&echo=0&child_of=' . $parentid . '&taxonomy=' . $taxonomy . '&include=' . $term_ids), array('<br />' => ' <br /> ')); 
echo preg_replace('@\s<br />\s\[email protected]', '', $terms); 
} 
?>        

現在我希望能夠做同樣的但沒有上面的代碼自動生成鏈接。有任何想法嗎?

回答

0

使用get_categories()代替wp_list_categories()

$terms = get_categories("child_of={$parentid}&include={$term_ids}"); 

foreach($terms as $term) 
    echo $term->name; 
+0

這工作。謝謝! – Armin

相關問題