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

I apologize if this is a dumb question, but I am just learning PHP and Wordpress. It's probably very simple.

I have a site where the top-level nav is all parent categories, with the child categories as dropdowns. The pages are all pulling from category.php.

On the child category pages, I would like to display the current child category page title (single_cat_title, I think) for styling, but I want to exclude this feature on the parent category pages.

I've been trying to write this very simply using get_the_category() as per this example in the codex:

$category = get_the_category(); echo $category[0]->cat_name;

Any help is greatly appreciated.

share|improve this question
up vote 0 down vote accepted

Add a check wherever you're displaying the title:

//Anything greater than 0 means the category has parents, 0 means no parent, child category
if($category->category_parent > 0){
    echo $category[0]->cat_name;

This should help.

share|improve this answer
thanks Rutwick. So I dropped ` $category = get_the_category(); if ($category->category_parent > 0) { ?> <h1><?php $category[0]->cat_name; } ?> </h1>` into my template, but nothing prints. Am I missing something? One thing I realized is that all the posts are assigned to multiple categories - could that be messing it up? (With the appropriate php tags open and close) – Max Mar 27 '12 at 4:54
Try a print_r on $category to check if its right – Rutwick Gangurde Mar 27 '12 at 5:11
Hi Rutwick - thank you again, that helped me work it out. – Max Mar 29 '12 at 22:11
You're welcome! Please accept the answer! ;) – Rutwick Gangurde Mar 30 '12 at 3:39

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.