Support » Themes and Templates » How to show only child categories using the_category();

  • Hi,

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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?

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Try it with this (inside the loop):

    <?php
      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> ';
        }
      }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to show only child categories using the_category();’ is closed to new replies.