Title: Category list of parent categories only
Last modified: August 18, 2016

---

# Category list of parent categories only

 *  [shaungraham](https://wordpress.org/support/users/shaungraham/)
 * (@shaungraham)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/category-lists/)
 * Is there a way to restrict the categories that show up in a category list ?
 * I have a list of categories in my side bar and would like to exclude all categories
   that are a child of other categories.
 * Is this possible ? And if so could you point me in the right direction.
 * Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/category-lists/#post-635980)
 * I thought the [template tag](http://codex.wordpress.org/Template_Tags), [wp_list_categories()](http://codex.wordpress.org/Template_Tags/wp_list_categories),
   would do it, but it doesn’t have a depth parameter so something like this:
 *     ```
       <?php
       $parent_cats = $wpdb->get_results("SELECT *
           FROM $wpdb->term_taxonomy
           WHERE taxonomy = 'category' AND parent = 0");
       foreach ($parent_cats as $parent) {
       $cat_name = get_the_category_by_ID($parent->term_id);
       echo '<a href="' . get_category_link($parent->term_id) . '" title="' . sprintf(__("View all posts in %s"), $cat_name) . '">' . $cat_name . '</a>
       ';
       }
       ?>
       ```
   
 *  [jwesseldyke](https://wordpress.org/support/users/jwesseldyke/)
 * (@jwesseldyke)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/category-lists/#post-636581)
 * I have tried every widget and suggestion known to man to get my categories to
   display the way I want them… Now I found this, and it looks like you’ve got the
   goods here… Only question is… Where does it go?
 * I’ve tried a hack for wp_list_categories which I’m sure would work… But I must
   be doing it wrong… I found it here… I also tried a css “trick” the same person
   mentioned but again, must have done something wrong… They suggested editing style.
   css to read .children {display:none} and that didn’t seem to do anything either…
 *  [zepponet](https://wordpress.org/support/users/zepponet/)
 * (@zepponet)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/category-lists/#post-636582)
 * I have used [Fold Category plugin](http://www.webspaceworks.com/resources/wordpress/31/)
   for that with WP 2.1, but I am not sure if it works also with WP 2.3?
 *  [jwesseldyke](https://wordpress.org/support/users/jwesseldyke/)
 * (@jwesseldyke)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/category-lists/#post-636583)
 * Yeah, I tried that, but either I wasn’t using it correctly or it didn’t work 
   with 2.3. Listing both the parent and child categories is cumbersome and confusing…
   I’d even be content with the menu tree, and I can’t get them to work either…
 *  [landersims](https://wordpress.org/support/users/landersims/)
 * (@landersims)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/category-lists/#post-636584)
 * Even with the Fold Categories plugin the “children=0” boolean doesn’t seem to
   work.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Category list of parent categories only’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [list](https://wordpress.org/support/topic-tag/list/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 5 participants
 * Last reply from: [landersims](https://wordpress.org/support/users/landersims/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/category-lists/#post-636584)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
