dongye4192 2012-03-18 13:36
浏览 208
已采纳

函数通过get_categories()函数显示wordpress中没有子类别的类别

I made this function to show the top navigation for my theme:

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;
  }

} 

but it shows all the categories and subcategories together, I tried to read in the codex site of wordpress to exclude only subcategories but I couldnt find anything!

  • 写回答

1条回答 默认 最新

  • douao8204 2012-03-18 13:42
    关注

    This should work

    $categories =  get_categories('hide_empty=0&style=none&parent=0'); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?