• Hello all,

    I am trying to set up a sub navigation using the archive.php page. I’ll like to have it look something like this:

    Parent Category
    Child Category 1
    Child Category 2
    Child Category 3
    Child Category 4

    I am having trouble figuring out how to get that info. For example, So I need the sidebar to query what category it is in, list that title and then list the children of that category. I don’t quite understand how the query loop on the archive page is working so am not quite sure how (or if) I can pass that variable to wp_list_categories.

    Here’s an example, right now how I list out the children of the category is with this:
    <?php wp_list_categories(‘orderby=id&title_li=0&child_of=3′,’

    • ‘,’
    • ‘); ?>

      So, I’d like to replace the ‘3’ for a variable that is using the category that is currently being browsed on archive.php. Make sense?

      Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Might not be exactly what you want, but try this:

    <?php
    //if a category archive display children of this category with wp_list_categories
    if (is_category( )) {
      $cat = get_query_var('cat');
      wp_list_categories('orderby=id&title_li=0&child_of='.$cat);
    }
    ?>

    Thread Starter misterpatrick67

    (@misterpatrick67)

    Thanks MichaelH,

    OK, I figured out with some tips in a different thread where you were responding yesterday I wrote a bit response and just discovered that I never hit ‘post’. Whoops. So here it is in summary. I’ll give your code a try as well.

    The solutions I figured out has a couple slight problems, so there is probably a better approach. I am having one slight problem. I am using deprecated function and I am getting an echo of the category ID. Here’s the code:

    <?php $cat_id = the_category_ID(); ?> //this is echoing the id number back onto the page
    <?php echo(get_category_parents($cat_id, TRUE, '  ')); ?>
    
    <?php wp_list_categories('orderby=id&title_li=0&child_of='.$cat_id); ?>

    The other problem other than the echoing of the cat id, is that once you actually select on of the children it often, but not always, changes the navigation. Here’s what I mean:

    Parent Category
      Child Category 1
      Child Category 2
      Child Category 3
      Child Category 4

    They’ll appear fine, and I can select most of the children and it will stay correct, but then in some categories the links will change to:

    Parent Category
    Child Category 3
    <em>No Categories</em>

    The Child category while have move up the chain and is getting the formatting of the top ul li not the styling of the children. It’s not consistent, so there is something weird in what I’m doing. All my categories consist of a parent category and children, none of the children and children. Make sense?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Listing Cateogries and Children in Archive’ is closed to new replies.