开发者

WordPress > wp_list_categories with no child categories listed

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)...

I thought the "depth"=1 argument would do the trick but not so. It lists ALL categories. When I remove the "heirarchical" argyument, it DOES exclude child categories, but then also includes the "uncategorized" category which I'm explicitly excluding via the exclude_tree = 1 argument.

At a loss. WordPress 3.0.1 tested.

    $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'开发者_如何学C, $cat_args));


add this $cat_args['child_of'] = 0; with combination of $cat_args['depth'] = 1;

It will generate o only root category

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


After some trial and error, this actually worked for me...

    $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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜