[英]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.