简体   繁体   English

在Wordpress中显示类别列表,不包含子类别

[英]Display categories list in Wordpress without subcategories

I am attempting to show categories in a list, but without displaying subcatgories. 我试图在列表中显示类别,但不显示子类别。 My current code is: 我当前的代码是:

 <?php if (is_category()) { $this_category = get_category($cat); if (get_category_children($this_category->cat_ID) != "") { echo "<ul>"; wp_list_categories('orderby=id&show_count=0&title_li= &use_desc_for_title=1&child_of='.$this_category->cat_ID); echo "</ul>"; } }?> 

Which displays the categories nicely 可以很好地显示类别

在此处输入图片说明

but when I added a sub-category it looked like this: 但是当我添加一个子类别时,它看起来像这样:

在此处输入图片说明

Any ideas? 有任何想法吗? Thanks! 谢谢!

Use get_categories() instead. 使用get_categories()代替。 https://developer.wordpress.org/reference/functions/get_categories/#Get_only_top_level_categories https://developer.wordpress.org/reference/functions/get_categories/#Get_only_top_level_categories

It has "parent" parameter which you can set to 0 and get desired result. 它具有“父”参数,您可以将其设置为0并获得所需的结果。

对我来说似乎是一个CSS问题:您可能希望隐藏子类别项目,直到其被单击或悬停为止

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM