How to Display Related Posts in WordPress

105

If you know anything about bounce rate, you are probably already showing related posts in WordPress. Bounce rate essentially represents the percentage of initial visitors to a site who “bounce” away to a different site, rather than continue on to other pages within the same site. This can have a significant impact on your adsense earning. By adding Related posts in WordPress you are killing three birds with one stone. You are decreasing your bounce rate, you are increasing your adsense income, and lastly you are increasing your pageviews. In this article we will show you how you can display related posts in WordPress with and without a plugin.

There are two methods of doing so and you can choose whichever method you prefer. One way is doing it without a plugin and then there is another method that is doing it with a plugin.

Display Related Posts in WordPress without a Plugin

Paste the following code in single.php where you want to display related posts

  <?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();  }  ?>

Source: MichaelH

Display Related Posts in WordPress with a Plugin

The plugin we use is called Yet Another Related Post Plugin (YARP). It gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site. Key features include:

  • 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.
  • Templating: New in 3.0! A new templating system puts you in charge of how your posts are displayed.
  • Caching: New in 3.0! YARPP now caches the related posts for all the posts and thus has significantly improved performance over versions 2.x.
  • Related posts in RSS feeds: Display related posts in your RSS and Atom feeds with custom display options.
  • 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.
  • Related posts and pages: Puts you in control of pulling up related posts, pages, or both.

Download YARP