1, This snippets works fine for non-logged users too.
2, I do not use any plugin for this simple feature, because it slow down the website. Snippets are great.
3, Example of the code Beers Pubs
4, Related posts are the best to create from tags of the post or categories, that is php logic of the function.
5, Markup based on Bootstrap 2.3.2
Related posts by tags:
<?php
// $current_post = $post;
//Call global variable posts
global $post;
//Save to variable all tags from the post ID
$posttags = wp_get_post_tags($post->ID);
//If the post has a tags
if ($posttags) {
//set up tags_ids as arrays
$tags_ids = array();
//loop through post tags from the current post and set array tags_ids save it from object posttags
foreach($posttags as $posttag) $tags_ids[] = $posttag->term_id;
//set arguments as array for the object wp_query
$args = array(
'tag__in' => $tags_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 4, // Number of related posts that will be shown.
'ignore_sticky_posts'=>1
);
//Set the new object and asign there an array of the arguments
$relatedposts = new wp_query( $args );
//loop
if( $relatedposts->have_posts() ) {
echo '<div class="related-posts clearfix"><h4>Related Posts</h4><div class="row-fluid">';
while( $relatedposts->have_posts() ) { $relatedposts->the_post(); ?>
<div class="span3">
<a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('relatedpost-image'); ?></a>
<span><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></span>
</div>
<? }
echo '</div></div>';
} //end of the post
} //end of if the post has tags
// $post = $current_post;
wp_reset_query();
?>