WordPress.org

Forums

[resolved] Display tags only if assigned to more than one post (5 posts)

  1. csleh
    Member
    Posted 6 years ago #

    is there a way to limit this:

    <?php the_tags(); ?>

    to only show if there are other posts with the same tag?

  2. MichaelH
    Member
    Posted 6 years ago #

    to only show if there are other posts with the same tag

    <?php
    $tags = wp_get_post_tags($post->ID);
      if ($tags) {
        foreach($tags as $tag) {
          if ($tag->count > 1) {
            echo '' . $title . '<a href="' . get_term_link( $tag->term_id, 'post_tag' ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a> is assigned to ' . $tag->count . ' posts.
     ';
          }
        }
      }
    ?>
  3. csleh
    Member
    Posted 6 years ago #

    Thank you!! Works perfectly

  4. afsender
    Member
    Posted 5 years ago #

    Great! But where to put the code?

  5. MichaelH
    Member
    Posted 5 years ago #

    First review Template Hierarchy...your theme's index.php or archive.php or category.php are possibilities.

Topic Closed

This topic has been closed to new replies.

About this Topic