我使用这段代码来显示分类法的描述。
<?php $my_taxonomy = \'institute\'; $terms = wp_get_post_terms( $post->ID, $my_taxonomy ); echo term_description($terms[0]->term_id, $my_taxonomy); ?>
如果我想显示子分类法甚至子分类法的描述,该怎么办?我使用这段代码来显示分类法的描述。
<?php $my_taxonomy = \'institute\'; $terms = wp_get_post_terms( $post->ID, $my_taxonomy ); echo term_description($terms[0]->term_id, $my_taxonomy); ?>
如果我想显示子分类法甚至子分类法的描述,该怎么办?术语描述仅适用于术语id和分类名称,因此如果要获取子术语的描述,应首先获取一个术语的所有子项(以及它们的子项,如果是另一个级别深的话),并使用单个term_description
按id呼叫。
<?php
$my_taxonomy = \'institute\';
$terms = wp_get_post_terms( $post->ID, $my_taxonomy );
echo term_description($terms[0]->term_id, $my_taxonomy);
//Assuming you have only 1 parent term, if multiple then loop over the $terms array
$term_children = get_term_children( $terms[0]->term_id, $my_taxonomy );
foreach($term_children as $term_child)
{
echo term_description($term_child->term_id, $my_taxonomy).\'<br />\';
}
?>
这应该会给你一个想法。我是否可以向特定的分类法添加一些自定义字段,以便在调用该分类法时,也应该显示附加到该分类法的自定义字段。