How to Display Related Posts in WordPress

Display Related Posts in WordPress

Related posts are those posts which are in relation to the current post and are most likely to be viewed by the current reader. All those posts which share the same topic is called related posts. For example the current post is more likely to boost SEO so all the posts which helps boosting the SEO will be its related posts.

Idea behind displaying the related posts

How the WordPress be instructed that some other post is related to the current post? Well, this is pretty easy. How? The related posts will be having the same category, tag or some custom Meta tag. So related posts can be fetched based on category, tag or some other Meta tags.

How to display related posts in WordPress?

In WordPress, which is the most used content management system (CMS), there is always a plug-in for implementing your idea. There are also pros and cons of using plug-ins in WordPress. The advantage is that the task is accomplished without any coding. And the disadvantage is slowing the website because extra CSS and Java Scripts related to the plug-in are also loaded with normal page load. Another disadvantage is security holes. Many websites hacked so far are due to security vulnerability in the plug-ins.

Display related post in WordPress with a plug-in

You can use the following Plugins to display related posts in WordPress.

  • Related posts for WordPress
  • WordPress related posts
  • Yet Another Related Post Plug-in
  • Contextual related posts
  • Yuzo related posts
  • Inline Related posts

Click here if you don’t know how to install a plugin in WordPress.

Display related posts without plug-in

To display the related posts without Plug-in, paste the following piece of code into single.php function in a suitable place  (after the comments usually).

//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo 'Related Posts';
$first_tag = $tags[0]->term_id;
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>

Source: MichaelH

Leave a comment