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.

The script below creates a listing of the categories in the site (excluding those in "uncategorized").

If possible, I'd like to modify it so that it only lists the top level categories (no child categories)...

    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    wp_list_categories(apply_filters('widget_categories_args', $cat_args));
share|improve this question
add comment

2 Answers

$cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
$cat_args['title_li'] = '';
$cat_args['exclude_tree'] = 1;
$cat_args['depth'] = 1;
wp_list_categories(apply_filters('widget_categories_args', $cat_args));

I added the 'depth' argument to your array. Check out the Codex Page for full documentation of the function.

share|improve this answer
    
Thanks Phil, that didn't work for me (in WP 3.0.1, it lists everything, including children). I was only able to get it to work using the answer I just provided. –  Scott B Sep 27 '10 at 15:43
add comment
up vote 1 down vote accepted

After some trial and error, this is what it took to make it work...

    $cat_args = array('orderby' => 'count');
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;
    $cat_args['exclude'] = 1;
    $cat_args['depth'] = 1;
    wp_list_categories(apply_filters('widget_categories_args', $cat_args));
share|improve this answer
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.