显示分配给按父子类别关系排序的帖子的类别(或来自其他分类法的术语)。类似于函数get\\u the\\u category\\u list(),它按名称对类别进行排序。此示例必须在循环内使用。
<?php
$taxonomy = \'category\';
// Get the term IDs assigned to post.
$post_terms = wp_get_object_terms(
$post->ID,
$taxonomy,
array(
\'fields\' => \'ids\'
)
);
// Separator between links.
$separator = \', \';
if ( ! empty( $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;
}
资料来源:
user contributed example 来自开发人员的代码参考。