Skip to content

Instantly share code, notes, and snippets.

@vajrasar
Created May 9, 2014 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vajrasar/f71f31c9aeb4ae7dc179 to your computer and use it in GitHub Desktop.
Save vajrasar/f71f31c9aeb4ae7dc179 to your computer and use it in GitHub Desktop.
To get child categories of parent in single post.
<?php
$category = get_the_category();
$category = get_category ($category[0]->cat_ID);
if ($category->cat_ID) {
if(!$category->category_parent) // if category has NO parent
$children = wp_list_categories("orderby=id&depth=0&hide_empty=0&title_li=&child_of=".$category->cat_ID."&echo=0");
else // if category has parent, show children of current category's parent
$children = wp_list_categories("orderby=id&depth=0&hide_empty=0&exclude=".$category->cat_ID."&title_li=&child_of=".$category->category_parent."&echo=0");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment