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();?

  • 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, 2011 at 18:33

1 Answer 1

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

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.