Display All Posts From the Same Category

Are you looking for a way to display a list of all the posts except the current post? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display other posts from the same category in WordPress.

All you have to do is add this code to your theme’s single.php file:

<?php
/* Display Other Posts From the Same Category  */
if ( is_single()) {
  $categories = get_the_category();
  if ($categories) {
    foreach ($categories as $category) {
      // echo "<pre>"; print_r($category); echo "</pre>";
      $cat = $category->cat_ID;
      $args=array(
        'cat' => $cat,   
        'order' =>'ASC',
        'post__not_in' => array($post->ID),
        'posts_per_page'=>-1,
        'caller_get_posts'=>1
      );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        //echo '<p>Check out our other '. $category->category_description .' </p>';   
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
        	<li class="cat-item cat-item-51"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
         <?php
        endwhile;
      } //if ($my_query)
    } //foreach ($categories
  } //if ($categories)
  wp_reset_query();  // Restore global post data stomped by the_post().
} //if (is_single())
?>