2017-07-28 83 views
0

我嘗試在每個類別的名稱末尾輸入帶有count的wordpress類別,方法是在代碼中輸入父類別。輸出wordpress列表類別,根據父類別的名稱計數

下面代碼的結果顯示類別與最後的帖子數,但它顯示所有類別。

例:我有一個父類別名稱 「阿爾法」,和它的子類別名稱是,類別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; 
?> 
+0

你的意思是說,在主父類權童總類數顯示父類? –

回答

0

我找到了答案,我只是在數組中使用「child_of」,並在值中輸入父類別ID。

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

顯示當前類別聰明的孩子類別,總髮帖量

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