WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Problems with tags display

[Resolved] Problems with tags display

  • Hi,
    I’ve modified a theme to my like. I created a CSS class to the post tags and searching, I found this: http://codex.wordpress.org/Function_Reference/get_tags. I’ve adapted this:

    <?php
    					$tags = get_the_tags();
    					foreach ($tags as $tag){
    						$tag_link = get_tag_link($tag->term_id);
    						$html .= "<a href=\"{$tag_link}\" title=\"{$tag->name} Tag\" class=\"tags\">";
    						$html .= "{$tag->name}</a>";
    					}
    				?>

    On the first post, the tags is correct. But on the second post or more (I display two posts per page), the tags of first post is repeated with the tags of second posts.
    How can I fix this?
    Thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • bcworkz

    @bcworkz

    Reset $html to an empty string before entering the foreach loop. This essentially discards th old tag data so you have a clean container for the next post.

    Oh! Thank you so much, my problem is resolved! 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Problems with tags display’ is closed to new replies.