可以向函数中添加函数。php并将“characters”作为参数(或自定义分类法的slug)传递,以显示所有术语的逗号分隔列表。
function show_all_terms($taxonomy){
$taxonomy_terms = get_terms($taxonomy);
foreach($taxonomy_terms as $term){
$terms[] = $term->name;
}
if(!empty($terms)) {
echo join(", ", $terms);
}
else{
echo "No ".$taxonomy."associated with this ".get_post_type();
}
}
现在,您可以在模板中调用此函数,如下所示:
show_all_terms(\'character\');
// you can replace \'character\' with the slug of any custom taxonomy as well.