• Resolved ewenc

    (@ewenc)


    Hi,

    In the blog I’m developing I’ve engineered some tabs which equate to the ‘top level’ categories found in the blog heirarchy. These appear throughout the site and are intended to offer more obvious navigation. When in a first level category, the sidebar category list is listing all the children categories of the current one which have entries and that’s working fine.

    However, on the home page, I’m wanting the sidebar to list just the top level categories, together with the post count for each. That’s not a problem and I make a different call to do that. This one in fact:

    wp_list_cats(“children=0&optioncount=1”);

    My problem is that what I would like it to do is to list each top level category and count essentially as a roll-up of itself and it child categories. In this way, I’d hope that a top level category would appear in the list even if it had no posts, so long as at least one of its child categories had a post. Additionally, I’d like the post count to be a roll up of the posts in all its child categories.

    I know there’s the option to display the child categories and to display all categories but, just to be difficult, I only want to display a category if there is at least one post somewhere down its category tree.

    While I made a nice mess of explaining it, it strikes me as being somthing that’s probably quite a common, or at least sensible, thing to want to do. As a result, I’ve looked through the codex and the forums to find info on some function or parameters to do it, but there doesn’t seem to be.

    I’m happy enough writing some php to do it myself, but if it can be done using the stock WP functionality then I’d much rather do that.

    Does anyone know if this can be done?

    Thanks!
    EwenC

Viewing 4 replies - 1 through 4 (of 4 total)
  • Pick at least one of the child cat posts, hit “edit this post,” check the box for the parent category as well, then hit “save.”

    Thread Starter ewenc

    (@ewenc)

    Thanks for this. Tried this but it’s not going to sort the problem – instead, the count’s still wrong – ir just 1 for the parent category (unless all child-category entries also go into the top level parent directory, but that’s be missing the point).

    The other issue is that I’d hoped that the category link under the post itself when seen in either the home page or another higher level category would show only the category to which the post truly belongs, and not also the top level cat as it does when added also to the top level one.

    Thread Starter ewenc

    (@ewenc)

    For completeness, I ended up putting modified versions of wp_list_cats and list_cats into a my-hacks file instead.

    I’m in the same boat: I have several parent categories. Some of these have children categories. In the site-wide navigation, I’d like all categories with posts–including child cats–to show in the navigation. I would prefer to NOT assign the post to both the parent and child cateory just to get the child cat to display. I also don’t want to use hide_empty=0 since that will display ALL cats even if there are no posts–the opposite of what I’m trying to achieve.

    So, is there a way to display ALL cats, including children, only where there are posts in the cats?

    THX!
    JF ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_list_cats – how to hide empty cats UNLESS their child categories have posts’ is closed to new replies.