WordPress >wp_list_categories 没有列出子类别 [英] WordPress > wp_list_categories with no child categories listed

查看:29
本文介绍了WordPress >wp_list_categories 没有列出子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的脚本创建站点中类别的列表(不包括未分类"中的类别).

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

我认为depth"=1 参数可以解决问题,但事实并非如此.它列出了所有类别.当我删除分层"参数时,它确实排除了子类别,但也包括我通过 exclude_tree = 1 参数明确排除的未分类"类别.

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.

不知所措.WordPress 3.0.1 已测试.

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

推荐答案

经过一些试验和错误,这实际上对我有用...

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

这篇关于WordPress >wp_list_categories 没有列出子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆