How to get other posts from same category in wordpress?

Being new to the wordpress its very difficult to add something new like showing other post from same category. I gave attempt to install few plugins but finally i got very good solution. Which’s is again quick and easy trick ;). So let’s move to topic how to get other posts from same category in wordpress/ current category post listing.

Two easy steps to add category post listing on post detail page.

Step 1: I have tested this code  in wordpress3.0. Go to the current theme of wordpress and find Post.php

Step 2: Edit this file and add following set of lines before comments or after add comment section.

$categories = get_the_category();
foreach($categories as $category) {
$ccid = $category->cat_ID;
$ccName = $category->cat_name;
break;
}
if($ccid) {
$args = array( 'numberposts' => 10, 'orderby' => 'rand', 'category' =>   $ccid);
$rand_posts = get_posts($args);
if(count($rand_posts)) {
echo "<strong>Popular Post from category $ccName </strong> <BR>";
echo "<ul>";
foreach( $rand_posts as $post ){ ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
}
echo "</ul>";
}
}

we are done Yuppie!!!

Share this nice post:

25 thoughts on “How to get other posts from same category in wordpress?

  1. So great to discover person with a number of initial ideas on it area. realy thanks for starting this up. this web site can be something is helpful on the internet, somebody with a little bit of inspiration. helpful work for bringing one thing new to the internet!

  2. I got what you intend, thanks for putting up. Woh I am willing to deed this website finished google.

Comments are closed.