Support » Fixing WordPress » Randomize related posts

  • I have some code in place that gets the tags of the current posts and displays a list of related posts with the associated thumbnail. The problem is that the many of the same posts are showing up again and again on different posts because its only displaying the top 5 results returned. I need to randomize it a little so that the related posts are more varied, but still related by tag. Here is the code:

    				$tags = wp_get_post_tags($post->ID);
    				if ($tags) {
    					$tag_ids = array();
    					foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
    						'tag__in' => $tag_ids,
    						'post__not_in' => array($post->ID),
    						'showposts'=>5, // Number of related posts that will be shown.
    					$my_query = new wp_query($args);
    					if( $my_query->have_posts() ) {
    						echo '<div class="related-posts"><h2>Stories You\'ll Love</h2>';
    						while ($my_query->have_posts()) {
    							<div class="related-post">
                                <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    							<?php show_thumb($width=110,$height=110,$crop='T',$quality=95,$blank=false); ?>
    							<?php the_title(); ?></a></div>
    						echo '<div style="clear:both"></div></div>';

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Randomize related posts’ is closed to new replies.