Sally在此基础上改进以显示帖子数量的道具
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
\'parent\' => $term->term_id,
\'hide_empty\' => false
) );
if ( $children ) {
foreach( $children as $subcat )
{
echo \'<li><a href="\' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . \'">\' . // wrapped
$subcat->name . \' (\' . $subcat->count . \')\' . \'</a></li>\';
}
}
更新
To show the posts count:
正如注释中所指出的,并且基于上述代码,您可以使用
$subcat->count
显示特定期限内的职位数量。
因此,我更换了$subcat->name . \'</a></li>\'
使用:
$subcat->name . \' (\' . $subcat->count . \')\' . \'</a></li>\'
输出如下内容:
Term Name (1)
,
Another Term Name (0)
, 等
For the original code in question (using wp_list_categories()
), here\'s how to fix it, and the fixed code:
<更换
is_category()
具有
is_tax( \'p_scales\' )
.
更换get_query_var( \'cat\' )
具有get_queried_object_id()
.
if (is_tax(\'p_scales\'))
{
$cur_cat = get_queried_object_id();
if ($cur_cat)
{
$new_cats = wp_list_categories(\'show_option_none=&echo=false&child_of=\' . // wrapped
$cur_cat . \'&depth=1&title_li=&show_count=1&hide_empty=1&taxonomy=p_scales\');
echo \'\' . $new_cats . \'\';
}
}