WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'm using the_category(); on my category.php template to show the category's name — the problem is that it attaches the category's parent category. Is there any way to show only child categories using the_category();?

share|improve this question
Please post an example of the code you're employing so that we can get a better idea as to what you're trying to accomplish/where you may be going awry. – ZaMoose Mar 12 '11 at 18:33
foreach((get_the_category()) as $category) {
    if ($category->category_parent  == '7') {
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf(__( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';

All you need to do is replace 7 with whatever category you want to include

share|improve this answer

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.