【问题标题】:function to show the categories without the subcategories in wordpress with the get_categories() function使用 get_categories() 函数在 wordpress 中显示没有子类别的类别的函数
【发布时间】:2012-03-18 13:36:54
【问题描述】:

我制作了这个功能来显示我的主题的顶部导航:

function costume_menu() {

$categories =  get_categories('hide_empty=0&style=none'); 
  foreach ($categories as $category) {
    $nav = '<li>';
    $nav .= '<a href="'.get_category_link($category->term_id).'">'.strtoupper($category->cat_name).'</a>';
    $nav .= '</li>';

    echo $nav;
  }

} 

但它同时显示了所有类别和子类别,我试图在 wordpress 的 codex 站点中阅读以仅排除子类别但我找不到任何东西!

【问题讨论】:

    标签: php wordpress menu


    【解决方案1】:

    这应该可行

    $categories =  get_categories('hide_empty=0&style=none&parent=0'); 
    

    【讨论】:

    • @IgorIvanovski Nice :) 不要忘记接受答案(关于这个问题,以及你问过的老年人)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多