Wordpress:仅显示顶级类别 [英] Wordpress: Show only TOP level categories

查看:46
本文介绍了Wordpress:仅显示顶级类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这段代码:

$args = 数组('orderby' =>'姓名','分层' =>1、'风格' =>'没有任何','分类' =>'类别','hide_empty' =>0,'深度' =>1、'title_li' =>'');$categories = get_categories($args);

我想要做的是仅列出顶级类别.当我使用这段代码时,我得到的不仅仅是一级.有人可以帮我吗?

解决方案

get_categories() 没有 depth 参数,你应该试试:

$args = 数组('orderby' =>'姓名','父母' =>0);

<块引用>

parent :(整数)仅显示由其 ID 标识的类别的直接后代(即仅子项)的类别.这不像 'child_of' 参数那样工作.此参数没有默认值.[2.8.4]

阅读更多:http://codex.wordpress.org/Function_Reference/get_categories#Get_only_top_level_categories

I am using this bit of code:

$args = array(
  'orderby' => 'name',
  'hierarchical' => 1,
  'style' => 'none',
  'taxonomy' => 'category',
  'hide_empty' => 0,
  'depth' => 1,
  'title_li' => ''
);

$categories = get_categories($args);

What I am trying to do is to list only top level categories. When I am using this code I am getting all of them not just level one. Can someone help me?

解决方案

There is no depth argument for get_categories(), you should try :

$args = array(
  'orderby' => 'name',
  'parent' => 0
);

parent : (integer) Display only categories that are direct descendants (i.e. children only) of the category identified by its ID. This does NOT work like the 'child_of' parameter. There is no default for this parameter. [In 2.8.4]

Read more : http://codex.wordpress.org/Function_Reference/get_categories#Get_only_top_level_categories

这篇关于Wordpress:仅显示顶级类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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