2017-06-21 73 views
2

我使用此代碼來顯示自定義職位分類層次,一切工作到現在很好,但我想實現也是顯示這些類別爲純文本(沒有<a href="...")。誰能幫忙?顯示自定義職位類別作爲計劃文本

    $taxonomy = 'produkte_kategorie'; // change this to your taxonomy 
        $terms = wp_get_post_terms($post->ID, $taxonomy, array("fields" => "ids")); 
        if($terms) { 
        echo '<ul class="p-kategorie">'; 
        $terms = trim(implode(',', (array) $terms), ' ,'); 
        wp_list_categories('title_li=&taxonomy=' . $taxonomy . '&include=' . $terms); 
        echo '</ul>'; 
        } 

回答

0

你可以做到這一點通過以下功能,

$terms = trim(implode(',', (array) $terms), ' ,'); 
$categories = get_categories(array('include'=>$terms,'taxonomy'=>'produkte_kategorie')); 

foreach ($categories as $category) { 
    echo $category->cat_name; 
} 
+0

我收到此錯誤:解析錯誤:語法錯誤,意外'=>'(T_DOUBLE_ARROW) – gencdoda

+0

忘了傳數組,加入代碼 –

0

其實這並沒有爲我工作,但我做了來自WordPress的抄本這個代碼的解決方案:https://developer.wordpress.org/reference/functions/wp_list_categories/

$分類='category';

//獲取分配給職位的術語ID。 $ post_terms = wp_get_object_terms($ post-> ID,$ taxonomy,array('fields'=>'ids'));

//鏈接之間的分隔符。 $ separator =',';

如果(!空($ post_terms)& & is_wp_error($ post_terms)!){

$term_ids = implode(',' , $post_terms); 

$terms = wp_list_categories(array(
    'title_li' => '', 
    'style' => 'none', 
    'echo'  => false, 
    'taxonomy' => $taxonomy, 
    'include' => $term_ids 
)); 

$terms = rtrim(trim(str_replace('<br />', $separator, $terms)), $separator); 

// Display post categories. 
echo $terms; 

非常感謝您的反饋

相關問題