[wp-trac] Re: [WordPress Trac] #2922: wp_list_cats() doesn't show categories with empty parents

WordPress Trac wp-trac at lists.automattic.com
Thu Jul 6 15:14:46 GMT 2006

#2922: wp_list_cats() doesn't show categories with empty parents
 Reporter:  ketsugi   |        Owner:  anonymous
     Type:  defect    |       Status:  reopened 
 Priority:  normal    |    Milestone:  2.1      
Component:  Template  |      Version:  2.1      
 Severity:  normal    |   Resolution:           
 Keywords:            |  
Changes (by BrianLayman):

  * milestone:  => 2.1


 Errrrr... No, it's not a plugin issue. A category containing a child
 category with posts is not empty.  That's how a hierarchy works.  Plus
 this was a known issue long before widgets showed up.  change sidepar.php
 to have hierarchical=1 and it does the same thing.  So, it is not a plugin

 I looked at fixing this back in March when I started my personal blog.  It
 has to do with how $hide_empty is processed in template-functions-
 category.php's function list_cats.

 This line doesn't have any info about a category's (potential) children:
 if ( ( intval($hide_empty) == 0 || $category->category_count) &&
 (!$hierarchical || $category->category_parent == $child_of) ) {

 I've actually thought about this one because I was going to log it an
 suggest a fix.  I was going to suggest that as the categories are loaded
 in functions.php's &get_category they modify their parent to increment its
 child_count property.

 To allow this &get_category would have to have its SQL statement modified
 to specify the fields and an extra one added called child_count with a
 hard coded value of 0.  This, I think, will modify the $category
 references correctly throughout the source.  Perhaps the category related
 functions called in admin-db.php will need to be tweaked too.  I've not
 looked at the code in depth yet.

 Then the pertenent line in list_cats would change to something like this:
 if ( ( intval($hide_empty) == 0 ||
 (($category->category_count)||$category->child_count)) && (!$hierarchical
 || $category->category_parent == $child_of) ) {

Ticket URL: <http://trac.wordpress.org/ticket/2922>
WordPress Trac <http://wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list