Filed Under: Wordpress

Wordpress: exclude subcategories

7 April 2008 2 Comments Tags: , , ,

If you are looking for a solution to exclude subcategories, here is a very simply way:

$categories= get_categories();
foreach ($categories as $cat) {
if($cat->category_parent == 0){
DO WHATEVER YOU WANT TO DO 
}
}

You could use this code to make a dropdown box without subcategories.
Here is the wordpress reference for “get_categories” with an example of a categories dropdown box.
Dropdown box







Like our posts? Then subscribe via Mail:

Email:  

Similar Posts:

Socialize:

delicious stumbleupon

2 Comments »

Leave your response!

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.com.