WordPress.org

Make WordPress Core

Changeset 4104


Ignore:
Timestamp:
08/17/06 04:46:16 (8 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category.php

    r4040 r4104  
    6868    $where .= $exclusions; 
    6969 
    70     if ( $hide_empty ) { 
     70    if ( $hide_empty && !$hierarchical ) { 
    7171        if ( 'link' == $type ) 
    7272            $where .= ' AND link_count > 0'; 
     
    104104        $categories = & _get_cat_children($child_of, $categories); 
    105105 
     106    // Update category counts to include children. 
     107    if ( $hierarchical ) { 
     108        foreach ( $categories as $k => $category ) { 
     109            $progeny = $category->category_count; 
     110            if ( $children = _get_cat_children($category->cat_ID, $categories) ) { 
     111                foreach ( $children as $child ) 
     112                    $progeny += $child->category_count; 
     113            } 
     114            if ( !$progeny && $hide_empty ) 
     115                unset($categories[$k]); 
     116            else 
     117                $categories[$k]->category_count = $progeny; 
     118        } 
     119    } 
     120    reset ( $categories ); 
     121 
    106122    return apply_filters('get_categories', $categories, $r); 
    107123} 
Note: See TracChangeset for help on using the changeset viewer.