How to show only child categories using the_category(); (3 posts)

  1. joaoramos
    Posted 4 years ago #


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

  2. stemie
    Posted 4 years ago #

    Did you find an answer.

    It boggles my mind that there is no easy to find solution out their.

    Its rather annoying as this must be very basic.

    Anyone know how to do this?

  3. keesiemeijer
    Posted 4 years ago #

    Try it with this (inside the loop):

      foreach((get_the_category()) as $category) {
        if ($category->category_parent  != 0) {
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr(strip_tags($category->name)) . '" ' . '>' . $category->name.'</a> ';

Topic Closed

This topic has been closed to new replies.

About this Topic