How to display the Parent categorie as a title. (4 posts)

  1. sren
    Posted 9 years ago #

    My problem is that I have a parent categorie with a lot of childs.
    The parent is empty, no posts at all.
    So WordPress displays the Parent as a link, and of course there will be a "not found" inside.
    What can I do to avoid that empty link in my categories listing ?
    (I'm using 2.0.4)

    Thanks a lot for any advice.

  2. ZMAng
    Posted 9 years ago #

    From what I know, this is pretty much unavoidable. If you turn off show_empty (i.e. you ask wp_list_cats not to show empty categories), then even your child categories will not show.

    However, you could work around this by excluding the empty category from your category list, and replacing it by calling another wp_list_cats. In this second category list, call only the children of that empty category. The code should look like this:

    <?php wp_list_cats('child_of=XX'); ?>
    where XX is the category ID of the empty parent category.

  3. sren
    Posted 9 years ago #

    Thanks ZMAng.
    Is an interesting idea.
    Another chance could be if I can separate category listings, so I wouldn't need an empty parent, and I could use an h2 tag for the title.
    So, the question would be if is it possible to include h2 labels in between categories.

    Thanks again.

  4. sren
    Posted 9 years ago #

    Found it on docs.

    I've added an "exclude" on the category I wanted on another part of the sidebar.
    And then,another h2 title, and a second wp_list_cats displaying only the childs of that category.
    This is achieved using the parameter "&child_of=cat_number".
    That way I simply ad my h2 tag and then I can list the categorie I want separated from the rest.

    The Codec is great, everything is there. I was just lazy.:)
    Thanks everyone.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.