Support » Plugins » How to remove duplicate categories on a tag template?

  • Cathy Tibbles


    When a user clicks on a tag link, I want to show them a list of the tagged post’s bottom-level categories(no descendants). (it sounds mixed up, but the bottom level cats are questions, the posts are each an answer to the question. I need to show the tagged posts’ bottom level cat/question.

    This code lists the bottom-level cat for each post in the tag template, BUT it lists the bottom level cat for EACH post, so where there are more than one posts to a cat, it lists the cat multiple times.

    Is there a way to remove duplicates? (An example: )

           <?php if( have_posts() ) : while( have_posts() ): the_post();
            foreach((get_the_category()) as $this_cat) {
              if (get_category_children($this_cat->cat_ID) == "") {
                 $name = $this_cat->cat_name;
                 $link = get_category_link($this_cat->cat_ID);?>
    <li><a href="<?php echo $link ;?>" title="<?php echo $name;?>"><?php echo $name; ?></a></li>
    <?php } }?>
    <?php endwhile;?>
    <?php endif;?>
  • The topic ‘How to remove duplicate categories on a tag template?’ is closed to new replies.