To increase page visit, time on site as well as decreasing bounce rate of a site or blog, related post is one and the most basic way to do it. It is important to provide this as menu to offer related contents that might be useful for reader. Normally you could use some wordpress plugin to provide such, but it is not a good idea if you use too much plugin since it could harm your server. As a solution, we can add this related post to our wordpress site manually. Please note this related post article is intended to blogs that use wordpress blogging platform, if you are using blogger please read Related Post with Icon Widget or another stylish related post that I've modified Carousel Related Post with Bubbled Thumbnail. There are two Related Post types you can use for your wordpress site, Related Post by Category and Related Post by Tag.
Related Post by Category
<h3>Related Post :</h3>
<?php $this_post = $post;$category = get_the_category(); $category = $category[0]; $category = $category->cat_ID;$posts = get_posts('numberposts=11&offset=0&orderby=rand&order=DESC&category='.$category);$count = 0;foreach ( $posts as $post ) {if ( $post->ID == $this_post->ID || $count == 10) {unset($posts[$count]);}else{$count ++;}}?>
<?php if ( $posts ) : ?>
<div><ol>
<?php foreach ( $posts as $post ) : ?>
<li><a href="<?php the_permalink() ?>">
<?php if ( get_the_title() ){ the_title(); } else { echo "No Related Post"; } ?></a></li>
<?php endforeach // $posts as $post ?>
</ol></div>
<?php endif // $posts ?>
<?php $post = $this_post;unset($this_post);?>
Related Post by Tag
<h3>Related Post : </h3>Choose what you like most and follow the steps below to append it:
<ul><?php//number of related post 5, customize it here
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$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(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a></li><?php endwhile; }} ?></ul>
- Copy one of those two related post code:
- Open single.php file in your theme directory. If you are editing from Wordpress Dashboard, click Appearance – Editor – Your theme name – then open single.php file.
- Find this code <?php the_content('Read the rest of this entry'); ?> or <?php the_content(); ?>. . These two code are default codes to call your blog post in wordpress, so put the related post code below it/ paste the code there.
- Until then your related post should work properly, but you may also customize the number of related post list you wish to appear in every page. The first code / related post by category shows 10 posts list ...(count == 10) and the second code shows 5 posts ...(showposts'=>5), simply change the number of posts list to your liking.