• Resolved oxygensmith

    (@oxygensmith)


    Hi folks,

    I’m fairly new to WordPress, and I’m wondering if I am using the child_of parameter correctly in wp_list_categories(). child_of is not working as I am expecting.

    Using this code:

    <?php wp_list_categories('&title_li=&showcount=1&use_desc_for_title=0&childof=6'); ?>

    …I can’t get it to display “just the subcategories of category 6.” The wp_list_categories seems to ignore the child_of parameter and display all categories — main categories and subcategories for entries.

    This seems like it would be really straightforward, so I can’t understand why it wouldn’t show up. I’m using the wp_list_categories command on a static page. I have a separate Page for each main category, because I have a page template for each of these categories:

    – about (category ID = 3)
    – media (category ID = 6)
    – writing (category ID = 4)
    – blog (category ID = 10)
    – news (category ID = 1)

    Each of my page templates uses <?php query_posts(‘category_name=thecategoryname’); ?> to fetch entries of its category. index.php is the template for the news, but writing.php is the template for entries given the category of writing, blog.php is the template for entries given the category of blog, etc.

    I do this because each “category” constitutes a section of the site, and each section has to look a little bit different and uses a second loop to loop through secondary content. Media is the only category with subcategories, though, so it is the Page and page template where I am deploying the wp_list_categories command.

    Can anyone please tell me if I am using the command correctly? And while I’m here, is this an efficient way to divide the site into sections (one template per category)?

    Thank you so much for your help!

    Rob

Viewing 2 replies - 1 through 2 (of 2 total)
  • You have a typo in the code example above (missing _ in child_of). Try:

    <?php wp_list_categories('&title_li=&showcount=1&use_desc_for_title=0&child_of=6'); ?>

    Thread Starter oxygensmith

    (@oxygensmith)

    OMG. I can’t believe it was such a simple syntax mistake. I didn’t notice it, so I jumped immediately to the conclusion that it was the context of the PHP statement. Thanks for setting me straight esmi – I’m glad this works so simply!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘child_of not limiting display of categories – maybe it’s my site structure?’ is closed to new replies.