gpt4 book ai didi

Wordpress:仅显示顶级类别

转载 作者:行者123 更新时间:2023-12-04 02:38:47 26 4
gpt4 key购买 nike

我正在使用这段代码:

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

$categories = get_categories($args);

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

最佳答案

没有depth get_categories() 的论据, 你应该试试 :

$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]



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

关于Wordpress:仅显示顶级类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15113247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com