WordPress > wp_list_categories 未列出子类别

发布于 2024-09-25 06:14:39 字数 524 浏览 1 评论 0原文

下面的脚本创建网站中的类别列表(不包括“未分类”中的类别)。

如果可能的话,我想修改它,以便它只列出顶级类别(没有子类别)...

我认为“深度”= 1 参数可以解决问题,但事实并非如此。它列出了所有类别。当我删除“heirarchical”参数时,它确实排除了子类别,但也包括了我通过 except_tree = 1 参数明确排除的“未分类”类别。

不知所措。 WordPress 3.0.1 已测试。

    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    $cat_args['depth'] = 1;
    wp_list_categories(apply_filters('widget_categories_args', $cat_args));

The script below creates a listing of the categories in the site (excluding those in "uncategorized").

If possible, I'd like to modify it so that it only lists the top level categories (no child categories)...

I thought the "depth"=1 argument would do the trick but not so. It lists ALL categories. When I remove the "heirarchical" argyument, it DOES exclude child categories, but then also includes the "uncategorized" category which I'm explicitly excluding via the exclude_tree = 1 argument.

At a loss. WordPress 3.0.1 tested.

    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    $cat_args['depth'] = 1;
    wp_list_categories(apply_filters('widget_categories_args', $cat_args));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

五里雾 2024-10-02 06:14:39

添加这个
$cat_args['child_of'] = 0;$cat_args['depth'] = 1; 组合

它将仅生成根类别

$cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
$cat_args['title_li'] = '';
$cat_args['exclude_tree'] = 1;
$cat_args['depth'] = 1;
$cat_args['child_of'] = 0;
wp_list_categories(apply_filters('widget_categories_args', $cat_args));

add this
$cat_args['child_of'] = 0; with combination of $cat_args['depth'] = 1;

It will generate o only root category

$cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
$cat_args['title_li'] = '';
$cat_args['exclude_tree'] = 1;
$cat_args['depth'] = 1;
$cat_args['child_of'] = 0;
wp_list_categories(apply_filters('widget_categories_args', $cat_args));
桃扇骨 2024-10-02 06:14:39

经过一番尝试和错误后,这实际上对我有用......

    $cat_args = array('orderby' => 'count');
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    $cat_args['exclude'] = 1;
    $cat_args['depth'] = 1;
    wp_list_categories(apply_filters('widget_categories_args', $cat_args));

After some trial and error, this actually worked for me...

    $cat_args = array('orderby' => 'count');
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    $cat_args['exclude'] = 1;
    $cat_args['depth'] = 1;
    wp_list_categories(apply_filters('widget_categories_args', $cat_args));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文