Showing related post in the single.php page
Description
This code will show the related post from the same category indicated. Place inside the single.php file under the post query and indicate the number of post that should be visible. In this example 5 is the number of post visible
This code will show the related post from the same category indicated. Place inside the single.php file under the post query and indicate the number of post that should be visible. In this example 5 is the number of post visible
HTML Source Code
<!--Related Post Query Starts-->
<?php
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<!--Post Attributes Starts-->
<!-- Post Attributes Ends-->
<?php }
wp_reset_postdata(); ?>
<!--Related Post Query Ends-->