[英]Display categories list in Wordpress without subcategories
我試圖在列表中顯示類別,但不顯示子類別。 我當前的代碼是:
<?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>"; } }?>
可以很好地顯示類別
但是當我添加一個子類別時,它看起來像這樣:
有任何想法嗎? 謝謝!
使用get_categories()代替。 https://developer.wordpress.org/reference/functions/get_categories/#Get_only_top_level_categories
它具有“父”參數,您可以將其設置為0並獲得所需的結果。
對我來說似乎是一個CSS問題:您可能希望隱藏子類別項目,直到其被單擊或懸停為止
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.