Title: kbuntu's Replies | WordPress.org

---

# kbuntu

  [  ](https://wordpress.org/support/users/kbuntu/)

 *   [Profile](https://wordpress.org/support/users/kbuntu/)
 *   [Topics Started](https://wordpress.org/support/users/kbuntu/topics/)
 *   [Replies Created](https://wordpress.org/support/users/kbuntu/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/kbuntu/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/kbuntu/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/kbuntu/engagements/)
 *   [Favorites](https://wordpress.org/support/users/kbuntu/favorites/)

 Search replies:

## Forum Replies Created

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

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Get parent category posts](https://wordpress.org/support/topic/get-parent-posts/)
 *  Thread Starter [kbuntu](https://wordpress.org/support/users/kbuntu/)
 * (@kbuntu)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/get-parent-posts/#post-1336226)
 * I figured it out myself. Damn …maybe I shouldn’t work 16 hours a day.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Showing subcategories of a parent page under subcategory](https://wordpress.org/support/topic/showing-subcategories-of-a-parent-page-under-subcategory/)
 *  [kbuntu](https://wordpress.org/support/users/kbuntu/)
 * (@kbuntu)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/showing-subcategories-of-a-parent-page-under-subcategory/page/2/#post-1200249)
 * Hi t31os,
 * Wonder if this thread is still active. I have the same problem as klarabella.
   
   I’ve used “akis” code but for whatever reason it show all the categories on some
   pages and sometimes it work as it supposed too.
 * You code works great however is it possible to show all the subcategories of 
   a parent a post is filed under instead showing all the parent categories?
 * Thank you.
 *   Forum: [Themes and Templates](https://wordpress.org/support/forum/themes-and-templates/)
   
   In reply to: [Display children categories for a specific parent that this post belongs to](https://wordpress.org/support/topic/display-children-categories-for-a-specific-parent-that-this-post-belongs-to/)
 *  [kbuntu](https://wordpress.org/support/users/kbuntu/)
 * (@kbuntu)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/display-children-categories-for-a-specific-parent-that-this-post-belongs-to/#post-1168376)
 * After implementing the code I have posted above I’ve noticed it will just show
   the current “Sub Category” of the post it was posted in and not my additional
   subcategories under the parent. In addition it won’t show the correct sub category
   when you are viewing the post and instead displays all the categories.
 * After searching around on the forums here is what I’ve found:
 *     ```
       <?php
       if (is_home()) {
       wp_list_categories('orderby=id&title_li=&depth=1');
       }
       else{
       $category = get_the_category();
       $cat_term_id = $category[0]->term_id;
       $cat_category_parent = $category[0]->category_parent;
       $listcat = wp_list_categories('echo=0&child_of='.$cat_category_parent.'&title_li=');
       $listcat = str_replace("cat-item-".$cat_term_id, "cat-item-".$cat_term_id." current-cat", $listcat);
       if ( in_category( $cat_term_id ) || post_is_in_descendant_category( $cat_term_id )) {
       echo $listcat;
       }
       }
       ?>
       </ul>
       ```
   
 * What does the code do: It lists all the parent categories on the Homepage. If
   you have created several subcategories it will display them in their belonging
   parent category and hide all other parent and their sub categories. The post 
   will show the correct subcategory (and other sub categories belonging to the 
   same parent category) but will exclude all the other sub and parent.
 * Hope the explanation makes sense. Paste the code in the sidebar and try it.
 *   Forum: [Themes and Templates](https://wordpress.org/support/forum/themes-and-templates/)
   
   In reply to: [Display children categories for a specific parent that this post belongs to](https://wordpress.org/support/topic/display-children-categories-for-a-specific-parent-that-this-post-belongs-to/)
 *  [kbuntu](https://wordpress.org/support/users/kbuntu/)
 * (@kbuntu)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/display-children-categories-for-a-specific-parent-that-this-post-belongs-to/#post-1168374)
 * In case somebody is interested. I’m not a programmer but it worked for me. I 
   have modified the code a bit so it just shows the parent category on the homepage.
 *     ```
       <?php
       $categoryList = array();
       foreach((get_the_category()) as $category) // build list of categories for this post
       {
       $categoryList[] = $category->cat_ID;
       }
       ?><ul><?php
       if (is_home()) {
       wp_list_categories('orderby=id&title_li=&depth=1'); // only show the parent categories on home page
       }
       else{
       wp_list_categories("title_li=&include=" . join(",", $categoryList)); // only show categories this post is in
       }
       ?>
       ```
   

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