2017-06-21 78 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; 

非常感谢您的反馈

相关问题