jcadima
10/28/2015 - 9:36 PM

Show categories posts of the current category

Show categories posts of the current category

REF:  http://wordpress.stackexchange.com/questions/100767/display-recent-posts-from-the-same-category-as-current-post-in-sidebar


<?php

 global $post;
$category = get_the_category($post->ID); 
$current_cat = $category[0]->cat_name; //This will get me the first category assigned to the current post but since every post has only ONE cat. assigned to, it's good enough
?>
<h3 class="wg-title2"><span>Recent Posts</span></h3>
<ul>
	<?php
$my_query = new WP_Query('category_name='.$current_cat.'&showposts=10');
while ($my_query->have_posts()) : $my_query->the_post();  ?>
      <li><a href="<?php the_permalink() ;  ?>"><?php the_title(); ?></a></li>
 <?php
unset($current_cat); //I'm not sure I need to unset this variable?
endwhile;
?>	
</ul>