[英]output wordpress list categories with count by name the parent category
我尝试通过在某个地方的代码中输入父类别来输出每个类别名称末尾带有count的wordpress类别。
下面的代码向下显示的结果显示类别,并在末尾显示帖子数,但显示所有类别。
例如:我有一个父类别名称“ alpha”,它的子类别名称是A类,B类,C类,D类
我想要输出显示:
-类别A(5)
-类别B(2)
-类别C(6)
-类别D(7)
<?php
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none'
) );
echo $variable;
?>
我找到了答案,我只在数组中使用“ child_of”,然后在值中输入父类别ID。
<?php
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none',
'hide_empty' => 0,
'child_of' => 52
) );
echo $variable;
?>
显示当前类别明智的子类别以及总数
<?php
$category_object = get_queried_object();
$current_category_taxonomy = $category_object->taxonomy;
$current_category_term_id = $category_object->term_id;
$current_category_name = $category_object->name;
$args = array(
'child_of' => $current_category_term_id,
'current_category' => $current_category_term_id,
'depth' => 0,
'echo' => 1,
'exclude' => '',
'exclude_tree' => '',
'feed' => '',
'feed_image' => '',
'feed_type' => '',
'hide_empty' => 0,
'hide_title_if_empty' => false,
'hierarchical' => true,
'order' => 'ASC',
'orderby' => 'name',
'separator' => '',
'show_count' => 1,
'show_option_all' => '',
'show_option_none' => __( 'No categories' ),
'style' => 'list',
'taxonomy' => 'category',
'title_li' => __( $current_category_name ),
'use_desc_for_title' => 0,
);
wp_list_categories($args);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.