Title: WP Category List
Last modified: August 20, 2016

---

# WP Category List

 *  [noeg](https://wordpress.org/support/users/noeg/)
 * (@noeg)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/wp-category-list/)
 * 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)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/wp-category-list/#post-2638190)
 * Could you use [get_ancestors](http://codex.wordpress.org/Function_Reference/get_ancestors)
   to test for an ancestor first and then drop the ancestor’s id into wp_list_category()?
 *  Thread Starter [noeg](https://wordpress.org/support/users/noeg/)
 * (@noeg)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/wp-category-list/#post-2638193)
 * 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?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/wp-category-list/#post-2638197)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/wp-category-list/#post-2638197)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
