Skip to main content

Beginner’s guide on how to display related posts in WordPress with or without plugin.

Why before how

Honestly, almost all the website displaying this stuff and you should do it too, because of this fantastic four reasons:

First: You will get more page views, because at the end of your post there will be a group of related posts that your reader might wanna take a look.

Second: It decrease your bounce rate. In simple words bounce rate is the representation of visitors that bounce away to the different website rather than keep exploring the same website.

Third: First and second implies that you will get more traffic to your website and that’s why you have created a website.

Four: It’s very easy to engage.

There are two ways of doing this stuff. First is to do it manually(without plugin) and second is with using the plugin.

*manually(without a plugin)

For instant, we can assume that you want to add related posts at the end of each blog post. This is the spot that i usually found on most of the website. If you want to add 3 related posts, we will compare the “tags” of the articles to get the related post, and it will be handy to display all 3 post inside a group.

smashing

Now, you should add these code after the end of your blog post tag, of course you can add it to wherever you wanna display the related posts The code follows as:


<div class="relatedposts">
	<h3>Related posts</h3>
	<?php
		$orig_post = $post;
		global $post;
		$tags = wp_get_post_tags($post->ID);
 
		if ($tags) {
			$tag_ids = array();
		foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
			$args=array(
				'tag__in' => $tag_ids,
				'post__not_in' => array($post->ID),
				'posts_per_page'=>4, // Number of related posts to display.
				'caller_get_posts'=>1
			);
 
		$my_query = new wp_query( $args );
 
		while( $my_query->have_posts() ) {
			$my_query->the_post();
		?>
 
		<div class="relatedthumb">
			<a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br />
			<?php the_title(); ?>
			</a>
		</div>
 
		<?php }
		}
		$post = $orig_post;
		wp_reset_query();
		?>
</div>

As of now we have a division that include 3 related posts at the end of each article or blog post, but at this very instance it looks boring.what lacking is css code to simply style your related posts just add below snippet to your css file.


.single .relatedposts .relatedthumb {
	display:inline-block;
	width: 32%;
}

With using a plugin:

It may happen that you don’t wanna get your hands dirty with php code, or may be you want to keep your single.php file clean, then i’m damn sure that you are looking for a plugin that can easily display related posts. After researching a lot the best plugin(as per my opinion) i found is YET ANOTHER RELATED POSTS PLUGIN(YARPP). There are several other great plugins are:

  • related posts
  • related posts via categories
  • related posts via taxonomies related posts via taxonomies

yer another related posts plugin

yarpp

YARPP is the most effective plugin that i found on almost all the famous blog. Personally i love it. What makes it best? I think the functionality that is used to display related posts with not only tags or categories. It even uses advanced and versatile algorithm and other factors to improve other features. Know more about YARPP Or download straight from the wordpress.org

related posts

related-post

It’s just a matter of time and clicks to get started with this amazing plugin.it will automatically link your posts with related content. Know more about this plugin at wordpress.org

related posts via categories

related-posts-via-categories

May some people go after the soley on the categories, then it’s worthwhile to download this plugin as it display the related posts via categories. Same as the name implies. Know more about this plugin at wordpress.org.

related posts via taxonomies

related-posts-via-taxonomies

This plugin will display the group of related post after each blog post, or you can get some custom setting to only display after the related posts. It based off the taxonomies and group of tags. Know more about this plugin at wordpress.org.