Currently I'm using the following code as part of sidebar code for Wordpress (the code works fine):
<ul class="linklist"> <?php $recentPosts = new WP_Query(); $recentPosts->query('showposts=12'); while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"> <?php the_title(); ?></a> </li> <?php endwhile;?> </ul>
It shows the last 12 posts. But what I'm looking for is the following; first check what category the current post (the post that is showing based on the permalink) belongs to, and then only list the latest posts that belong to that same category. What should be edited? Thanks!
Take a look at http://codex.wordpress.org/Function_Reference
It sounds like you are going to want get_the_category(). (Posts can belong to multiple categories). Then you are going to want to call get_posts() passing in the category flag and whatever else you want.