• I’ve been reading threads similar to my questions for the past hour but I think I need to have it answered personally so I could understand it better. The problem is I’m developing a theme with a css drop down menu if I click a link from a specific parent category the top of the selected category it should list the other child categories in a nice horizontal menu. I found this reference earlier

    $cat_id = get_query_var('cat');
    
    wp_list_categories('orderby=id&title_li=&child_of=' . $cat_id);

    I put this into my category.php file and it works but when I click into one of the child cats I want the list to stay there so the visitor could select another sub category if they choose. Is there something better to use other then what I put above?

    I was also thinking maybe I could create different page templates for each category and register menus for each parent category to list its children so when I click the children the list stays the same I’m just looking for the easiest way to do it

Viewing 3 replies - 1 through 3 (of 3 total)
  • Could you use get_ancestors to test for an ancestor first and then drop the ancestor’s id into wp_list_category()?

    Thread Starter noeg

    (@noeg)

    not that great at this so I add

    <?php get_ancestors( $object_id, $object_type ); ?>

    into the category.php file and what on there do I change?

    Something like:

    <?php
    $cat_id = get_query_var('cat');
    $ancestors = get_ancestors( $cat_id,  'category' );
    if( $ancestors[0] == 0 ) wp_list_categories('orderby=id&title_li=&child_of=' . $cat_id);
    else {
    	$ancestor = end($ancestors);
    	wp_list_categories('orderby=id&title_li=&child_of=' . $ancestor);
    }
    ?>

    Bear in mind that this is off the top of my head, so it’s not tested.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP Category List’ is closed to new replies.