Opened 7 years ago
Closed 7 years ago
#2922 closed defect (bug) (fixed)
wp_list_cats() doesn't show categories with empty parents
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.1 |
| Component: | Template | Version: | 2.1 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
I'm using the Sidebar Widgets plugin. The issue here is with the Categories widget, which according to my settings makes this function call:
wp_list_cats("sort_column=name&optioncount=1&hierarchical=1")
I have three categories with posts: two are top-level ("Blog" and "Software") and another is a child ("Software" --> "Plugins").
If "Plugins" has posts, but "Software" has no posts, the wp_list_cats function call only shows the "Blog" category. "Plugins" is not shown despite having posts within it.
Change History (7)
comment:3
ketsugi
— 7 years ago
Sorry, I should've looked at the documentation earlier to find out that "hideempty" is set to TRUE by default.
comment:4
ketsugi
— 7 years ago
- Resolution invalid deleted
- Status changed from closed to reopened
Wait a minute, I almost got thrown off my original bug report there. The problem is not with the plugin not calling hideempty. The problem is that wp_list_cats() doesn't show the "Plugins" category, which does have posts inside. I can understand hiding the empty "Software" category, but its children categories should be shown if they have posts, instead of hiding the entire tree of categories simply because the parent is empty on that level.
comment:5
BrianLayman
— 7 years ago
- Milestone set to 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 thing.
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:
| $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:
| (($category->category_count) | $category->child_count)) && (!$hierarchical | $category->category_parent == $child_of) ) { |
comment:6
BrianLayman
— 7 years ago
Note that all of the OR symbols and the parens that were touching them were removed from that post... use your imagination and you can figure out where they go...
This is a problem with the plugin and not wordpress itself.