2

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));
2

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));
0
$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.

  • 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

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.