How to Call Related Posts in WordPress

Add this into your single post template, and call related posts based on category.

<?php
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not_in' => array($post->ID) ) );

if( $related ) foreach( $related as $post ) {
setup_postdata($post); 
?>
<ul>
<li>

<?php the_post_thumbnail( 'blog-feed-thumbnail' ); ?>

<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>

<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">Read more ></a>

</li>
</ul>   
<?php 
}
wp_reset_postdata(); 
?>
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments