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 ?



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.

    'style' => 'none',
    'orderby' => 'name',
    'show_count' => true,
    'hierarchical' => true,
    'depth' => 1
$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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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