Title: Display post by category
Last modified: August 19, 2016

---

# Display post by category

 *  [drossie](https://wordpress.org/support/users/drossie/)
 * (@drossie)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/display-post-by-category/)
 * Just wondering if anyone could tell me how to make the following code display
   posts of only the current catergory. At the moment it displays post from all 
   catergories.
 *     ```
       <?php $recent = new WP_Query("cat=$current_category&showposts=2"); while($recent->have_posts()) : $recent->the_post();?>
       <?php if( get_post_meta($post->ID, "hpbottom", true) ): ?>
       " rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "hpbottom", true); ?>" alt="<?php the_title(); ?>" />
       <?php else: ?>
       " rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php bloginfo('template_url'); ?>/images/thumbnail.png" alt="<?php the_title(); ?>" />
       <?php endif; ?>
       <b>" rel="bookmark"><?php the_title(); ?></b>
       <?php the_content_limit(350, "[Read more of this review]"); ?>
   
       <div style="border-bottom:1px dotted #2255AA; margin-bottom:10px; padding:0px 0px 10px 0px; clear:both;"></div>
   
       <?php endwhile; ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/display-post-by-category/#post-940832)
 * Assuming you have a value in $current_category try
 * `<?php $recent = new WP_Query('cat=' . $current_category . '&showposts=2');`

Viewing 1 replies (of 1 total)

The topic ‘Display post by category’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/display-post-by-category/#post-940832)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
