Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

<?php
if (is_category()) {
?>
<div id="bodywrap">
<div id="sub-nav" class="wrap">    
<?php    
$this_category = get_category($cat);
if($this_category->category_parent){
    $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category-        >category_parent."&echo=0");
}
else{
$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>
<div class="clearboth"></div>
<div id="bodywrap">
<?php
}

?>
share|improve this question
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.