so I am trying to use the category.php to do all this, and basically I have 3 main/parent categories,

Dream it. Build it. Get The Hell Out.

and will have many sub-categories under them. What im trying to do is display the title / and related image etc of the parent category through-out the parent and sub-categories so for example : If I am in a sub-cat that is under the parent cat "Dream It", it will still say the title / related styles from the parent. I hope this makes sense.

right now I'm messing with and trying to achieve this like so , here is the code:

<div id="cat-area">
if (is_category('dream-it'))
{echo '<h1>Dream It.</h1>';}
if (is_category('build-it'))
{echo '<h1>Build It.</h1>';}
if (is_category('get-the-hell-out'))
{echo '<h1>Get The Hell Out!</h1>';}

But of course when i go into a sub cat, its just blank, could this maybe be achieved by using an else if, or somthing? any help would be amazing! thank you so much!

1 Answer 1


If you have a single level of subcategories under your main categories, you can just do this:

$category = get_category( $cat );
if( $category->category_parent ):
    $parent = get_cat_name( $category->category_parent );
    echo '<h1>' . $parent . '</h1>';
    echo '<h1>' . $category->cat_name . '</h1>';
  • This works great! can use this to echo say an image? instead of an h1? Commented Sep 9, 2011 at 17:28
  • @TheFragileMachine: You can display anything you want. $category->category_parent contains the parent category ID, you can look up everything related to that category with it. How you do know what image should be displayed for each main category?
    – Jan Fabry
    Commented Sep 10, 2011 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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