Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking to print out All of the Main Categories (So Exclude Sub-Categories) in a Loop, I need to get the ID's to do some advanced category listings.

So I need to echo this out:

3 CatName
4 CatName
5 CatName
x CatName

Where the number is the category # and the CatName is the name of the category

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

http://codex.wordpress.org/Function_Reference/get_categories

example:

<?php 
foreach(get_categories('parent=0&orderby=id') as $cat) { 
   echo $cat->term_id.' '.$cat->name.'<br/>'; 
} 
?>
share|improve this answer
    
Perfect Thanks! –  Jordash Aug 13 '11 at 4:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.