不知道我哪里出错了,请帮忙吗?
$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
//then set the args for wp_list_categories
$args = array(
'child_of' => $current_term->term_id,
'taxonomy' => $current_term->taxonomy,
'hide_empty' => 0,
'hierarchical' => true,
'depth' => 1,
'title_li' => __(''),
'echo' => '0'
);
$terms_list = wp_list_categories( $args);
if( $terms_list ){
?>
<div id="terms_list">
<ol>
<?php echo $terms_list; ?>
</ol>
</div>
<?php
};
// this line is just here for debug to confirm that we have the right item - it is not a part of the design or normal functionality
echo '<h1>terms_id: ' . $current_term->term_id . ' name: ' . $current_term->name . ' and: ' . $current_term->taxonomy . '</h1>';
?>
所以引起问题的函数是wp_list_categories(),它什么都没有返回。我已经检查过这个词是正确的,它确实有帖子,而且它确实有孩子也有帖子。安迪帮助赞赏!
答案 0 :(得分:0)
$current_term->term_id
的类型为 string 。 child_of
参数需要整数。
尝试这样做:
$args = array(
'child_of' => (int) $current_term->term_id,
'taxonomy' => $current_term->taxonomy,
'hide_empty' => 0,
'hierarchical' => true,
'depth' => 1,
'title_li' => __(''),
'echo' => '0'
);