Wordpress:显示没有 Link 的子类别名称

Wordpress: Display Subcategory Name Without Link

我有这段代码非常适合显示我选择的特定父类别的子类别名称和 link:

<?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
$categories = get_the_category();
$parentid = '6';

if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {

$term_ids = implode( ',' , $post_terms );
$terms = strtr( wp_list_categories( 'title_li=&style=none&echo=0&child_of=' . $parentid . '&taxonomy=' . $taxonomy . '&include=' . $term_ids), array( '<br />' => ' <br /> ' ) );
echo preg_replace( '@\s<br />\s\n$@', '', $terms );
}
?>                            

现在我希望能够做同样的事情,但不需要上面的代码自动生成 link。有什么想法吗?

使用get_categories()代替wp_list_categories()

$terms = get_categories("child_of={$parentid}&include={$term_ids}");

foreach($terms as $term)
    echo $term->name;