显示自定义职位类别作为计划文本
问题描述:
我使用此代码来显示自定义职位分类层次,一切工作到现在很好,但我想实现也是显示这些类别为纯文本(没有<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>';
}
答
你可以做到这一点通过以下功能,
$terms = trim(implode(',', (array) $terms), ' ,');
$categories = get_categories(array('include'=>$terms,'taxonomy'=>'produkte_kategorie'));
foreach ($categories as $category) {
echo $category->cat_name;
}
答
其实这并没有为我工作,但我做了来自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;
非常感谢您的反馈
我收到此错误:解析错误:语法错误,意外'=>'(T_DOUBLE_ARROW) – gencdoda
忘了传数组,加入代码 –