WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is some code that I have mixed together from around the web, what I am wanting it to do is show the sub-categories of what ever category it is in.

It seems to work on category, and sub-categories but wont show in the post its self.

if (is_category()) {
<div id="bodywrap">
<div id="sub-nav" class="wrap">    
$this_category = get_category($cat);
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category-        >category_parent."&echo=0");
$this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category-            >cat_ID."&echo=0");
if ($this_category) { 
    echo "<ul class=\"subnav\">". $this_category . "</ul>"; 
    echo "</div><div class=\"clearboth\"></div>";

else {

<div id="sub-nav" class="wrap">
<h2 title="<?php bloginfo( 'description', 'display' ); ?>"><?php bloginfo( 'description' ); ?></h2>
<div class="clearboth"></div>
<div id="bodywrap">

share|improve this question

The reason it only works on category and sub-category pages is because is_category() checks to see if a Category archive page is being displayed. However a post is not an "archive page" it is a "single page" (see http://codex.wordpress.org/Template_Hierarchy). So you would need to add another condition in there that first checks to see if you are on a post page - using is_single() - and if so then retrieves the posts parent category and displays the sub-categories for that parent category.

share|improve this answer
I so wish I was sure on how to do that! But thanks for the answer! – Chaos67731 Mar 8 '13 at 17:05
After looking at it, I have found very simple code that does that main point of the code above, but I am still running in to the problems of trying to get the main category sub-categories when on a single post. . I hope I sade that right? – Chaos67731 Mar 8 '13 at 17:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.