Title: Recent Post thumbnail
Last modified: August 20, 2016

---

# Recent Post thumbnail

 *  Resolved [nbatioco](https://wordpress.org/support/users/nbatioco/)
 * (@nbatioco)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/recent-post-thumbnail/)
 * I already have this code working that display 6 recent new post in my website.
 *     ```
       <?php
         $thumbnails = get_posts('numberposts=6');
         foreach ($thumbnails as $thumbnail) {
           if ( has_post_thumbnail($thumbnail->ID)) {
             echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
             echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail');
             echo '</a>';
           }
         }
       ?>
       ```
   
 * But I have one problem, like if I have a new post in my portfolio it well display
   also as my recent post. Can someone help me with the proper code that it will
   only show the recent post from a certain category or a parent category?
 * Thanks in advance.

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/recent-post-thumbnail/#post-2524037)
 * You can add the category id as a parameter:
 *     ```
       $thumbnails = get_posts('numberposts=6&cat=34');
       ```
   
 * Replace 34 with the id of your category.
 * See the other parameters available here:
 * [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
 *  Thread Starter [nbatioco](https://wordpress.org/support/users/nbatioco/)
 * (@nbatioco)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/recent-post-thumbnail/#post-2524155)
 * Thanks for the help vtxyzzy! But it gives me 12 more images lol.. But still thanks,
   I have look on the parameters and made them work.
 * Here’s my new code:
 *     ```
       <?php
         $thumbnails = get_posts(array('numberposts' => 6, 'category__not_in' => array(15)));
         foreach ($thumbnails as $thumbnail) {
           if ( has_post_thumbnail($thumbnail->ID)) {
             echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
             echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail');
             echo '</a>';
           }
         }
       ?>
       ```
   
 * Check how it looks like here [WordPress Best Themes](http://www.nbatioco.com)

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

The topic ‘Recent Post thumbnail’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [nbatioco](https://wordpress.org/support/users/nbatioco/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/recent-post-thumbnail/#post-2524155)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
