Update category counts to include children. Don't hide empty parent cats that have non-empty children. Props skeltoac.

git-svn-id: https://develop.svn.wordpress.org/trunk@4104 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2006-08-17 04:46:16 +00:00
parent f2e7bbb410
commit a313da93d7
1 changed files with 17 additions and 1 deletions

View File

@ -67,7 +67,7 @@ function &get_categories($args = '') {
$exclusions = apply_filters('list_cats_exclusions', $exclusions, $r );
$where .= $exclusions;
if ( $hide_empty ) {
if ( $hide_empty && !$hierarchical ) {
if ( 'link' == $type )
$where .= ' AND link_count > 0';
else
@ -103,6 +103,22 @@ function &get_categories($args = '') {
if ( $child_of || $hierarchical )
$categories = & _get_cat_children($child_of, $categories);
// Update category counts to include children.
if ( $hierarchical ) {
foreach ( $categories as $k => $category ) {
$progeny = $category->category_count;
if ( $children = _get_cat_children($category->cat_ID, $categories) ) {
foreach ( $children as $child )
$progeny += $child->category_count;
}
if ( !$progeny && $hide_empty )
unset($categories[$k]);
else
$categories[$k]->category_count = $progeny;
}
}
reset ( $categories );
return apply_filters('get_categories', $categories, $r);
}