WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to avoid duplicated tags on index.php ? (3 posts)

  1. modeman
    Member
    Posted 1 year ago #

    Hello, in my theme index.php i display tags box with tags from custom post type "katalogas". How to avoid duplicated tags?

    My tags loop code: http://pastebin.com/4jCNw1X8

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Why not just show random (post) tags? Something like this:

    // display 5 random tags
    $tags = get_terms('post_tag');
    if($tags) {
      $out = '';
      $rand_keys = array_rand($tags, 5);
      foreach ($rand_keys as $key) {
        $out .= '<a href="' . get_term_link( $tags[$key], 'post_tag' ) . '"';
        $out .= ' title="' . esc_attr(sprintf( __( "View all posts in %s" ), $tags[$key]->name )) . '">';
        $out .= '<span>'. $tags[$key]->name.'</span></a><br/>';
      }
      echo $out;
    }
  3. modeman
    Member
    Posted 1 year ago #

    Thanks, worked nice :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.