posts - how to limit and display tag?

Hi i need to show random 3 tags for a post. all my posts have been tagged with more than 10 tags, i need to display any

Hi i need to show random 3 tags for a post. all my posts have been tagged with more than 10 tags, i need to display any 3 tags randomly.

for eg:

A sample post

<a href="/tag1">Tag1</a>
<a href="/tag2">Tag2</a>
<a href="/tag3">Tag3</a>

I am currently using <?PHP the_tags()?> to generate all tags how to restrict it to 3 randomly generated tags.

Hi i need to show random 3 tags for a post. all my posts have been tagged with more than 10 tags, i need to display any 3 tags randomly.

for eg:

A sample post

<a href="/tag1">Tag1</a>
<a href="/tag2">Tag2</a>
<a href="/tag3">Tag3</a>

I am currently using <?PHP the_tags()?> to generate all tags how to restrict it to 3 randomly generated tags.

Share Improve this question asked Aug 17, 2011 at 5:32 EzhilEzhil 3897 silver badges20 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Try this:

   $posttags = get_the_tags();
   $count=0;
   if ($posttags) {
       foreach($posttags as $tag) {
          $count++;
          echo '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a> ';
          if( $count >4 ) break;
       }
   }
$count = 0;
$terms = get_terms( array(
    'taxonomy' => 'post_tag',
    'hide_empty' => true,
) );

foreach($terms as $term) {
    $term_link = get_term_link( $term );
    $count++;
    <a href="echo $term_link" class="size-1"> echo $term->name </a>;
    if ( $count >36 )
        break;
}   

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744848407a4596982.html

相关推荐

  • posts - how to limit and display tag?

    Hi i need to show random 3 tags for a post. all my posts have been tagged with more than 10 tags, i need to display any

    2天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信