简体   繁体   English

输出带有按名称计数的wordpress列表类别父类别

[英]output wordpress list categories with count by name the parent category

I try to output wordpress categories with count at the end of each category's name by input the parent category in code somewhere. 我尝试通过在某个地方的代码中输入父类别来输出每个类别名称末尾带有count的wordpress类别。

The result of the code down below display categories with the count of posts at the end, but it display all categories. 下面的代码向下显示的结果显示类别,并在末尾显示帖子数,但显示所有类别。

Ex: I have a parent category name "alpha", and its child categories name are, Category A, Category B, Category C, Category D 例如:我有一个父类别名称“ alpha”,它的子类别名称是A类,B类,C类,D类

I want the output display: 我想要输出显示:

-Category A (5) -类别A(5)

-Category B (2) -类别B(2)

-Category C (6) -类别C(6)

-Category D (7) -类别D(7)

<?php
    $variable = wp_list_categories( array(
    'show_count' => true,
    'orderby'    => 'name',
    'style'      => 'none'
    ) );
    echo $variable; 
?>

I found the answer, I just use the "child_of" in the array, and input the parent category ID in the value. 我找到了答案,我只在数组中使用“ child_of”,然后在值中输入父类别ID。

<?php
   $variable = wp_list_categories( array(
     'show_count'         => true,
     'orderby'             => 'name',
     'style'               => 'none',
     'hide_empty'         => 0,
     'child_of'            => 52
   ) );
   echo $variable; 
?>

Display current category wise child category with total post count 显示当前类别明智的子类别以及总数

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM