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

git-svn-id: http://svn.automattic.com/wordpress/trunk@4104 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-08-17 04:46:16 +00:00
parent 8bfa80dcf4
commit f2ae26089d
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);
}