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 am using this code to show a list of all categories in sidebar

<?php wp_list_cats('list=0&sort_column=name&optioncount=0&hierarchical=0&optioncount=1&children=0'); ?>

but the problem is that is lists the child categories as well. so the final result using the above code is like :
- category 1
- category 2
- child-category 1

I do not want the child-category 1 to be displayed - any suggestion on how ?

thanks

share|improve this question

3 Answers 3

up vote 1 down vote accepted

wp_list_cats is deprecated. You should switch to the "newer" version wp_list_categories which also supports some additional options. For example the depth option, which is probably what you're looking for. See the WordPress codex for more information.

wp_list_categories(array(
    'style' => 'none',
    'orderby' => 'name',
    'show_count' => true,
    'hierarchical' => true,
    'depth' => 1
));
share|improve this answer
    
thank you ! it was exactly what I wanted ;) –  Dave Aug 8 '12 at 19:56
<?php 
$args = array(
'depth' => 1,
'style' => 'none',
'orderby' => 'name'
); 
wp_list_categories( $args ); 

?>

wp_list_cats is deprecated so don't use it as it may stop working in the future. Instead use wp_list_categories with the above arguments and it will do it automatically. Depth => 1 will make it only show top level categories.

Some of your arguments in what you posted contradict themselves so I'm not sure what exactly you want, but this should pretty much do it. If you want it to show a count for how many posts in each category add 'show_count' => 1 to the $args array.

share|improve this answer
    
thanks for the help –  Dave Aug 8 '12 at 19:56

Try this &exclude='category id here'

<?php wp_list_categories('depth=1&hide_empty=1&orderby=ID&exclude=23,25&order=ASC&title_li=');  ?>

its working.... must try this

share|improve this answer

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.