Created
May 9, 2014 11:20
-
-
Save vajrasar/f71f31c9aeb4ae7dc179 to your computer and use it in GitHub Desktop.
To get child categories of parent in single post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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