Skip to content

Instantly share code, notes, and snippets.

@vajrasar
Last active August 29, 2015 14:01
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/291a6d6decefb8f000da to your computer and use it in GitHub Desktop.
Save vajrasar/291a6d6decefb8f000da to your computer and use it in GitHub Desktop.
To get child category of parent in archives
<?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