How to Show Related Post in WordPress?

0
380
How to Show Related Post in WordPress

Posts are usually the content prepared by users to provide information about certain topics to the visitors. Simply, posts can be a blog, an article or a tutorial. In various websites, you can view that when you finish reading a post, there are many other related posts displayed as a recommendation. Do you want to Show Related Post in WordPress? 

The main objective of showing related post is to let the visitors explore more to the ideas and views of the contents. Showing related post benefits the website by engaging the visitors to your site and build a strong connection. 

The related post can be displayed as a recommendation to the visitors.

In this tutorial, we will learn to display/show related post in WordPress. There are two major ways to display post.

  • Using Plugin
  • Without Using Plugin

We will briefly learn to do it with both the methods. Let’s Start:

Show Related Post in WordPress using Plugin

As we all know, the use of the plugin is simple and easy. When you do it from the plugin, the simple steps include installing the plugin and two or three more steps click.

Install and activate the Yet Another Related Post Plugin (YARPP). The plugin allows you to display the list of posts and pages related to the current post. To Install and Activate the plugin, follow our tutorial guide on ‘How to Install a new WordPress Plugin

After the plugin is activated, 

  • Click on Settings>>YARPP
  • On the display options for your website, choose the option of Posts.
  • Lastly, save the changes. 

Show Related Post in WordPress without using Plugin

For many WordPress users, installing and activating plugins can be unfavourable. For those, it is possible to even do without the use of the plugin. There are just a bunch of codes to add in single.php where you want to display related post. 

<?php

//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;

$args=array(

‘tag__in’ => array($first_tag),

‘post__not_in’ => array($post->ID),

‘posts_per_page’=>5,

‘caller_get_posts’=>1

);

$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>

<?php

endwhile;

}

wp_reset_query();

}

?>

With this, the related posts get displayed on your WordPress website. You can do it with either of the ways that sound okay to you. 

Easy, Simple and Quick!

For more articles and tutorial related to WordPress, Click here

LEAVE A REPLY

Please enter your comment!
Please enter your name here