PhotoDune

get_the_tags Help

2149 posts
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Exclusive Author
  • Germany
  • Has been a member for 3-4 years
  • Interviewed on the Envato Notes blog
+4 more
crozer says

Heyall,
here it goes:

I have this:
<?php $posttags = get_the_tags();
                        $count=0;
                        if ($posttags) 
                        {
                            foreach($posttags as $tag) 
                            {
                                  $count++;
                                  if ($count <= 3) 
                                  {
                                       echo $tag ?> name . ', ';
                                  }
                                  if ($count == 3)
                                  {
                                      echo $tag -> name . '..';
                                  }
                             }
                        }
                        ?> 

But it does not fully work. What I attempted with the ==3 part was to add a ’...’ after the third tag. Any ideas?

Thanks :)

947 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Ireland
  • Sold between 10 000 and 50 000 dollars
EireStudio says
Heyall,
here it goes: I have this:
&lt;?php $posttags = get_the_tags();
                        $count=0;
                        if ($posttags) 
                        {
                            foreach($posttags as $tag) 
                            {
                                  $count++;
                                  if ($count <= 3) 
                                  {
                                       echo $tag ?&gt; name . ', ';
                                  }
                                  if ($count == 3)
                                  {
                                      echo $tag -> name . '..';
                                  }
                             }
                        }
                        ?&gt; 

But it does not fully work. What I attempted with the ==3 part was to add a ’...’ after the third tag. Any ideas?

Thanks :)
Try this…
if ($count < 3) 
{
      echo $tag ?> name . ', ';
}
if ($count == 3)
{
      echo $tag -> name . '..';
 }
2149 posts
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Exclusive Author
  • Germany
  • Has been a member for 3-4 years
  • Interviewed on the Envato Notes blog
+4 more
crozer says

Thanks mate, it did work.

May I ask you, if there’s a hack to individualize tags called from get_the_tags.

I have the code above (with the fixed solution you provided). I would like each tag to be a single tag in style (so that I can apply a :hover state which only applies to ONE of the tags, and not the whole group.

Any ideas?
Thanks again :D!

by
by
by
by
by