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

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!

share|improve this question
up vote 1 down vote accepted

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>';
share|improve this answer
This works great! can use this to echo say an image? instead of an h1? – The Fragile Machine Sep 9 '11 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 Sep 10 '11 at 19:44

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.