[resolved] show links to all child categories in parent category page (7 posts)

  1. shovi
    Posted 9 years ago #

    I'm developing a directory-style article website and WordPress is by far the best way to set up the site (lots of flexibility for formatting, etc). However, one issue I'm having is that if you don't have a post in a category that category won't show up in your menu.

    we've hard-coded all the menu items to correspond with their parent and child category, so here's what I need to do...

    when you click on a parent category I want to be able to show - above any posts within that category - a complete list of child categories whether they have a post or not. Not sure how to do this, please help.


  2. MichaelH
    Posted 9 years ago #

    Have you looked at the 'hide_empty' parameter for the template tag, wp_list_categories?

    Additional resources:
    Stepping into Templates

    Also some plugins in this thread:

  3. shovi
    Posted 9 years ago #

    cool, that the hide_empty parameter worked (sort of)...one more thing (only because I'm on a deadline and it's a little cumbersome searching this support forum...)

    if I use
    <?php wp_list_categories('orderby=name&hide_empty=0&child_of=8'); ?>
    how can I replace "8" with a dynamic category variable, so that whatever category I'm viewing I can only see those child categories (and that would mean when I'm at the deepest level this menu won't show at all right?)?

    I'd also need to format the whole thing, but I found some relatively straightforward documentation on the wp_list_categories page.


  4. shovi
    Posted 9 years ago #

    okay, new approach...I am creating category-#.php pages in my theme files and want to drop the child categories using wp_list_categories at the top of each category-#.php page. this will give me a title page for all my topics, but leave the rest of the blog alone.

    two issues combined into one...wordpress doesn't recognize the category-#.php (# is obviously replaced) file. I'm using permalinks instead of index.php?cat=#, is there a setting I'm screwing up? and once that's fixed, can I use that code above (and hard-code the category # in the child_of attribute) and get this to work?

    hardly a dynamic approach to this, but hey, whatever works. thanks to the community for your help!

  5. kajsa
    Posted 9 years ago #


    <?php wp_list_categories("orderby=name&hide_empty=0&child_of=$parentcat"); ?>

  6. shovi
    Posted 9 years ago #

    didn't work, but I fixed it thanks! and for anyone else interested here's what I did:

    * created a category.php Template for all of my child categories, which didn't have the PHP code above.

    * created a category-#.php Template for each of the main categories, and instead of $parentcat above I put the category #.

    * styled the category-#.php Template to look nice, using info from the wp_list_categories documentation page.

  7. reviewabc
    Posted 8 years ago #

    Hi Showi, could you please post what is the example of website that already used your tricks?
    I want to see it :)

    Thanks and best regards

    John Chan

Topic Closed

This topic has been closed to new replies.

About this Topic