WordPress > wp_list_categories 未列出子类别
下面的脚本创建网站中的类别列表(不包括“未分类”中的类别)。
如果可能的话,我想修改它,以便它只列出顶级类别(没有子类别)...
我认为“深度”= 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加这个
$cat_args['child_of'] = 0;
与$cat_args['depth'] = 1;
组合它将仅生成根类别
add this
$cat_args['child_of'] = 0;
with combination of$cat_args['depth'] = 1;
It will generate o only root category
经过一番尝试和错误后,这实际上对我有用......
After some trial and error, this actually worked for me...