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

时间:2015-05-21 22:33:15

标签: wordpress taxonomy

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

<?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 );
}
?>                            

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

1 个答案:

答案 0 :(得分:0)

使用get_categories()代替wp_list_categories()

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

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