Displaying related posts below every WordPress post is a very great way to help visitors staying longer on your blog. You can use a plugins to automatically display related posts, but you also can use tags and a custom code to show related posts. Let’s see how to do it.
It’s advised to use minimum wordpress plugin to make your wordpress fast.
This code will display related posts based on the current post tag(s). You need to add the below code to your single.php file.
<?php $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), 'showposts'=>5, // Number of related posts that will be shown. 'caller_get_posts'=>1 ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo '<h3>Related Posts</h3><ul>'; while ($my_query->have_posts()) { $my_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php } echo '</ul>'; } } ?>
Checkout your WordPress post,now your blog posts will be looking cool
with this related post widget.
very nice article as this will not involve any plugin so wordpress blog will load up fast also.
Great info! I recently came across your blog and have been reading along. I thought I would leave my first comment. I don