Igor Ivanovski
Igor Ivanovski

Reputation: 415

function to show the categories without the subcategories in wordpress with the get_categories() function

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!

Upvotes: 1

Views: 2065

Answers (1)

Dogbert
Dogbert

Reputation: 222060

This should work

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

Upvotes: 5

Related Questions