Title: Shortcode for SHOW 2 POSTS
Last modified: August 19, 2016

---

# Shortcode for SHOW 2 POSTS

 *  Resolved [aceofjames](https://wordpress.org/support/users/aceofjames/)
 * (@aceofjames)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/shortcode-for-show-2-posts/)
 * I have been trying to get this shortcode to work properly for me to no avail.
 * I want it to show posts from a specific category but only show 2 posts. This 
   code shows all the posts in the category instead of 2 as I specify in the code.
 * `
    function category_shortcode( $atts ) { extract(shortcode_atts(array( 'limit'
   => '2', 'category' => '', ), $atts)); //The Query query_posts('category=' . $
   id . 'posts_per_page=' . $limit); //The Loop if ( have_posts() ) : while ( have_posts()):
   the_post(); echo '<h3><font color = blue> New Article:</font></h3>'; echo the_content();
   endwhile; else: endif;
 *  //Reset Query
    wp_reset_query(); } add_shortcode('category', 'category_shortcode');
 * I use this shortcode on the page:
 * [category id=3 limit=2]
 * This shows all the posts instead of just two. Any idea what I am doing wrong?
 * I am using shortcode because every query I did to display posts was not working.
 * Basically I just need to show the two most recent posts in full on a specific
   page. I can use shortcode or a custom template.
 * Can anyone help me out?
 * Thank you in advance!
 * James

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/shortcode-for-show-2-posts/#post-1829654)
 * there is an ampersand `&` missing before `posts_per_page=`:
 *     ```
       query_posts('category=' . $id . '&posts_per_page=' . $limit);
       ```
   
 * this might be all, or there could be more; just try to fix this first and see
   what changes.
 *  Thread Starter [aceofjames](https://wordpress.org/support/users/aceofjames/)
 * (@aceofjames)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/shortcode-for-show-2-posts/#post-1829720)
 * Hey Alchymyth!
 * That fixed it!
 * Thanks and Merry Christmas!
 * AceOfJames

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Shortcode for SHOW 2 POSTS’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [aceofjames](https://wordpress.org/support/users/aceofjames/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/shortcode-for-show-2-posts/#post-1829720)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
