Last active
August 29, 2015 14:01
-
-
Save vajrasar/291a6d6decefb8f000da to your computer and use it in GitHub Desktop.
To get child category of parent in archives
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 | |
$cat = get_query_var('cat'); | |
$category = get_category ($cat); | |
if(is_archive()) { | |
?> | |
<div id="bread-cat-list-archive"> | |
<h2><?php echo $category->name; ?></h2> | |
<?php | |
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"); | |
if ($children) { | |
echo "<h5>More Categories: </h5>" . $children; | |
} | |
} | |
?> | |
</div> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment