WordPress:如何从一个类别中获得第一级子级?

发布于 2024-09-12 18:05:22 字数 386 浏览 1 评论 0原文

我想知道是否有一个函数只返回第一级子类别子项。

Cat 1
   Sub-1.1
   Sub-1.2
       Sub-1.2.1
Cat 2
   Sub-2.1

这里我只想要:Sub-1.1、Sub-1.2 和 Sub-2.1

因为使用带有 child_of 参数的 get_categories 会给我带来所有子节点,直到最后一个节点:

get_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);

谢谢

I want to know if has a function that return only the first level of subcategories children.

Cat 1
   Sub-1.1
   Sub-1.2
       Sub-1.2.1
Cat 2
   Sub-2.1

Here I want only: Sub-1.1, Sub-1.2 and Sub-2.1

Cause using get_categories with child_of parameter brings me all children until the last node:

get_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID);

Thanks

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

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

发布评论

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

评论(1

來不及說愛妳 2024-09-19 18:05:22

请尝试

wp_list_categories(array('depth' => 2));

Please try

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