• Hi. I’ve been searching around on the forums and Google, but haven’t found an answer to this yet (I might be using the wrong keywords).

    I would like to code into the template a conditional statement that effectively says, if this category has children, list the children (as LIs in a MENU), AND/OR if this category is a child, list it and the other children of the same parent. If the conditions return false–if the cat is neither a parent nor a child, just a bachelor category :-), don’t show anything.

    It sounds so easy, and I HAVE been able to make it work with pages, but I can’t nail the category part–at least, not without hardcoding the category ID into the template, which I don’t want to do.

    Could someone please give me the code I’d need to use?

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I saw this plugin recently which might do what you’re looking for:

    http://wordpress.org/extend/plugins/wp-dtree-30/

    Thread Starter iamPariah

    (@iampariah)

    Thanks, Paul, but that isn’t really what I need. The WP-dTree plugin will make a tree view of categories (etc.). What I want is to return just a list of subcategories when viewing the parent.

    For example another WP 2.6.x site I worked on. You can see the second nav bar at the top, showing the sub-pages of “Training”. That second nav bar only appears if the page has child pages, and then only shows the child pages; if you are on a child page, it shows the siblings.

    Obviously I figured out how to do this with a relatively simple query for pages, but I need the same functionality for categories and their children. I just can’t get the right code for it.

    Please help? Anyone?

    Im looking for this also.

    _bump_

    Thread Starter iamPariah

    (@iampariah)

    This should almost do it, Anabelle. The only thing I haven’t been able to figure out yet is how to get the cat link and name into the LI.

    <?php
    $categories = get_categories("child_of=" . $cat->cat_ID . "&title_li=&hide_empty=true&orderby=ID&style=none&exclude=" . $excludecats );
    foreach ((array) $categories as $cat) {
    $cat_link = '<a href="' . get_category_link($cat->cat_ID) . '" title="' .
    sprintf(__("View %s"), $cat->cat_name) . '" ' . $rel . '>' . $cat->cat_name.'</a>';
    $cat_descrip = $cat->category_description;
    ?>
    
    <li class="item <?php echo $cat->slug; ?>">[insert cat name and link here]</li>

    Can’t seem to get that code working either, iamPariah..

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display conditional child category menu’ is closed to new replies.