• Resolved mortifrog

    (@mortifrog)


    Firstly, I made a post regarding this in Plugins / Hacks at
    http://wordpress.org/support/topic/412855

    but I’m not sure I posted in the correct board, so apologies for posting twice on the same subject, but I’m not sure if I explained myself properly in the first post anyway.

    It strikes me that when tags are displayed underneath a post, it seems pretty pointless to display a tag if the only post it has associated with it is the post you are reading. I think it makes more sense to suppress the displaying of tags until they have two or more posts associated with them. I have managed to achieve this is a single post by modifying my theme’s (Mystique) single.php from:

    <?php
                  $tags = array();
                  $i = 0;
                  foreach($post_tags as $tag):
    
                   $tags[$i] .=  '<a href="'.get_tag_link($tag->term_id).'" rel="tag" title="'.sprintf(__('%1$s (%2$s topics)'),$tag->name,$tag->count).'">'.$tag->name.'</a>';
    		    $i++;
    
                  endforeach;
                  echo implode(', ',$tags); ?>

    to:

    <?php
                  $tags = array();
                  $i = 0;
                  foreach($post_tags as $tag):
    		if($tag->count > '1')
    		    {
                   $tags[$i] .=  '<a href="'.get_tag_link($tag->term_id).'" rel="tag" title="'.sprintf(__('%1$s (%2$s topics)'),$tag->name,$tag->count).'">'.$tag->name.'</a>';
    		    $i++;
                        }
    
                  endforeach;
                  echo implode(', ',$tags); ?>

    This works fine for when you are looking at a post’s actual page – but when that post appears on the main home page, all the tags are displayed, including those with only 1 post associated with them.

    Can anyone tell me where the code is that generates the tag links when they are displayed on a multipost page? Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter mortifrog

    (@mortifrog)

    OK, whilst waiting for an answer I managed to work it out for myself.
    🙂
    The code I needed to edit was in core.php in my theme’s lib directory.

    Within that file I just searched for $tag->count and pulled the same trick as I did in single.php.

    Sorry if that’s obvious to some of you, but I’m pretty new to WP.

Viewing 1 replies (of 1 total)
  • The topic ‘Suppress tags with only 1 post associated’ is closed to new replies.