WordPress

Displaying Related Posts in WordPress

Providing Related Posts at the end of your posts or somewhere within the post is very beneficial. By inserting related posts, you’re attracting the visitors to read more of your blog posts. It also helps in reducing the Bounce Rate and also enhances the earnings from Advertisements.  We’ll show you to how to insert related posts in your WordPress Blog.

There are two methods of showing related posts – By using a Plugin or By inserting the code manually.

Display Related Posts By Using a Plugin (Easy):

There are many plugins available at Plugin Repository, but the best one we found is  Yet Another Related Post Plugin (YARPP). It key features include:

  1. An advanced and versatile algorithm: Using a customizable algorithm considering post titles, content, tags, and categories, YARPP calculates a “match score” for each pair of posts on your blog. You choose the threshold limit for relevance and you get more related posts if there are more related posts and less if there are less.
  2. Templating: The YARPP templating system puts you in charge of how your posts are displayed.
  3. CachingImproved in 3.2! YARPP organically caches the related posts data as your site is visited, greatly improving performance.
  4. Related posts in RSS feeds: Display related posts in your RSS and Atom feeds with custom display options.
  5. Disallowing certain tags or categories: You can choose certain tags or categories as disallowed, meaning any page or post with such tags or categories will not be served up by the plugin.
  6. Related posts and pages: Puts you in control of pulling up related posts, pages, or both.

If you don’t want to insert Related Posts directly at the end of every post, you can customize that too.

Displaying Related Posts without Plugin (Difficult):

If you don’t want to use a plugin, you can show up Related Posts by inserting a few lines of code. Though, there’s no official code provided by WordPress, many people have written codes to show the Related Posts. Here’s the one which works perfectly. You need to insert the code in your single.php file where you want the Related posts to appear.

<?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),
'showposts'=>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();
}
?>

Add Comment

Click here to post a comment

Email me when somebody replies to my comment.

Subscribe for email updates!

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 4,247 other subscribers