Inspiration For Creative Minds
Home » Labs » How to show related posts by category in WordPress  

Filed under Labs

Below code will display related post from the same category. You need to make changes according to your needs, in this example it will display title and post excerpt. Add the code on your WordPress template.

	$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 10, 'post__not_in' => array($post->ID) ) );
	if( $related ) foreach( $related as $post ) {
	setup_postdata($post); ?>
				<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
				<?php the_excerpt();?>
	<?php }
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook

Posts you may like: