WordPress> wp_list_categories without categories of children

Below is a list of scripts that contains a list of categories on the site (excluding those listed in the "without heading" section).

If possible, I would like to change it so that it only displays top-level categories (without child categories) ...

I thought the argument "depth" = 1 would do the trick, but not like that. It lists ALL categories. When I remove the “hierarchical” argumentation, it excludes the child categories, but then also includes the “uncategorized” category, which I explicitly exclude with the exclude_tree = 1 argument.

Into the abyss. Check WordPress 3.0.1.

    $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));
+3
source share
2 answers

   $cat_args['child_of'] = 0; $cat_args['depth'] = 1;

o

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

...

    $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

Source: https://habr.com/ru/post/1766783/


All Articles