<?php $tags = get_the_tags(); ?>
<?php if($tags): ?>
<?php $related = get_related_posts($post->ID, $tags); ?>
<?php if($related->have_posts() && get_option('pyre_related') == 'On'): ?>
<?php $count = 1; ?>
<div class="post-box">
<h4>Related Posts</h4>
<?php while($related->have_posts()): $related->the_post(); ?>
<?php if($count == 4): $count = 1; endif; if($count == 3): $class = 'last'; else: $class = ''; endif; ?>
<?php if(has_post_thumbnail()): ?>
<div class="related-item <?php echo $class; ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?> </a><span class="comments"><?php comments_popup_link('0', '1', '%'); ?></span>
<?php endif; ?>
<?php $count++; endwhile; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
//code in functions.php (defines get_related_posts function) :
function get_related_posts($post_id, $tags = array()) {
$query = new WP_Query();
if($tags) {
foreach($tags as $tag) {
$tagsA[] = $tag->term_id;
}
}
$args = wp_parse_args($args, array(
'showposts' => 3,
'post__not_in' => array($post_id),
'tag__in' => $tagsA,
'ignore_sticky_posts' => 1,
));
$query = new WP_Query($args);
return $query;
}