wordpress - wp_list_categories 取决于所选标签

标签 wordpress woocommerce wp-list-categories

我想显示一个类别列表,其中每个类别中当前的帖子数取决于所选标签。

例如,如果选择标签 A(已标记 2 个帖子),则类别列表将为:

- cat A (2)
-- cat Aa (1)
-- cat Ab (1)

如果选择标签 B(已标记 3 个帖子):

- cat A (3)
-- cat Aa (1)
-- cat Ab (1)
-- cat Ac (1)

由于无法在 wp_list_categories 的参数中指定标签,您有关于如何处理的想法吗?

谢谢

最佳答案

您有一堆可以应用 wp_list_categories 函数的参数。其中之一是 show count,它是一个 bool 值 0 -> false,1 -> true。还要检查 child_of 参数。

$args = array(
    'show_option_all'    => '',
    'orderby'            => 'name',
    'order'              => 'ASC',
    'style'              => 'list',
    'show_count'         => 0,
    'hide_empty'         => 1,
    'use_desc_for_title' => 1,
    'child_of'           => 0,
    'feed'               => '',
    'feed_type'          => '',
    'feed_image'         => '',
    'exclude'            => '',
    'exclude_tree'       => '',
    'include'            => '',
    'hierarchical'       => 1,
    'title_li'           => __( 'Categories' ),
    'show_option_none'   => __( '' ),
    'number'             => null,
    'echo'               => 1,
    'depth'              => 0,
    'current_category'   => 0,
    'pad_counts'         => 0,
    'taxonomy'           => 'category',
    'walker'             => null
);
wp_list_categories( $args ); 

https://codex.wordpress.org/Template_Tags/wp_list_categories

关于wordpress - wp_list_categories 取决于所选标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33433218/

相关文章:

wordpress - 引导菜单不适用于 WordPress

javascript - 将每个选择选项值转换为值列表

php - 使用 Bootstrap 为 `wp list` 类别设置样式

javascript - 如何在 jQuery 中仅定位当前悬停的元素

php - wp_list_categories 显示当前帖子的类别

css - Wordpress 类别的样式

php - 在 add_post_meta 中存储 Json 值

wordpress - 无法在 docker-compose 中添加对 docker volume 的写入权限

symfony1 - Symfony 作为 Wordpress 插件开发的助手

javascript - 如何在 woocommerce 之后添加自定义 JavaScript?