• I’d like for the hide_empty options in list_cats and wp_list_cats to not hide categories which are empty, but that have sub-categories that have posts in them.

    Or to prevent the function from being changed at it’s root, perhaps a configuration option to toggle my above suggestion.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am experiencing the same problem. It occurs whenever a categorie doesn’t contain any posts, but one or several of it’s subcategories do. Looking at the code it is obvious why this happens (template-functions-category.php, line 322). I can think of a quick fix for this though. Maybe someone can come up with one.

    I just came up with an idea and here is the result. I hope the support forums’ system preserves this in usable form:

    317a318,330
    > if ( $hide_empty ) {
    > $query = “
    > SELECT category_parent, SUM(category_count) AS category_child_count
    > FROM $wpdb->categories
    > WHERE cat_ID > 0 $exclusions
    > GROUP BY category_parent”;
    >
    > $cat_child_counts = $wpdb->get_results($query);
    > foreach ( $cat_child_counts as $cat_child_count ) {
    > $category_child_counts[“$cat_child_count->category_parent”] = $cat_child_count->category_child_count;
    > }
    > }
    >
    322c335
    < if ( ( intval($hide_empty) == 0 || $category->category_count) && (!$hierarchical || $category->category_parent == $child_of) ) {

    > if ( ( intval($hide_empty) == 0 || $category->category_count || $category_child_counts[$category->cat_ID]/*cat has non-empty children*/ ) && (!$hierarchical || $category->category_parent == $child_of) ) {

    The code from the last post is NOT well tested BTW!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘list_cats / wp_list_cats: hide_empty not hide cats with non-empty sub-cats’ is closed to new replies.