Title: 4 random thumbnails
Last modified: August 20, 2016

---

# 4 random thumbnails

 *  Resolved [Sinopa](https://wordpress.org/support/users/sinopa/)
 * (@sinopa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/)
 * Does anyone know how I can display 4 random thumbnails from post images.
    I want
   to display these thumbnails in my heading.

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

 *  Thread Starter [Sinopa](https://wordpress.org/support/users/sinopa/)
 * (@sinopa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230151)
 * And no one knows? 🙁
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230152)
 * example:
 *     ```
       <?php $thumb_posts = get_posts(array('orderby' => 'rand', 'numberposts' => 4, 'meta_key' => '_thumbnail_id' ));
       if($thumb_posts) { ?>
       <div class="header-thumbs">
       <?php foreach( $thumb_posts as $post ) {
       echo get_the_post_thumbnail($post->ID,array(240,170));
       } ?>
       </div>
       <?php }
       wp_reset_postdata(); ?>
       ```
   
 * [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
   
   [http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail](http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail)
 *  Thread Starter [Sinopa](https://wordpress.org/support/users/sinopa/)
 * (@sinopa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230153)
 * Thank you alchymyth, but that didn’t work. No thumbnails are shown 🙁
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230154)
 * worked for me in my local testsite;
 * have you posts with the featured image assigned?
 * can you post the full code of whatever template you added the code to?
    (please
   use the [http://pastebin.com/](http://pastebin.com/) – simply follow [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code))
 * a link to your site?
 *  Thread Starter [Sinopa](https://wordpress.org/support/users/sinopa/)
 * (@sinopa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230155)
 * With featured image assigned?
 * Here’s the link to the code at pastebin [http://pastebin.com/VPbvmtku](http://pastebin.com/VPbvmtku).
   
   It’s the the code from “It smells like facebook” theme.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230156)
 * > With featured image assigned?
 * where else would your thumbnail come from?
 * [http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature](http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature)
 *  Thread Starter [Sinopa](https://wordpress.org/support/users/sinopa/)
 * (@sinopa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230157)
 * Sorry. Missunderstood. I have posts with the featured image assigned.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230158)
 * here is a re-written version, using different wordpress codes:
 * [http://pastebin.com/QfLCgaBn](http://pastebin.com/QfLCgaBn)
 *  Thread Starter [Sinopa](https://wordpress.org/support/users/sinopa/)
 * (@sinopa)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230159)
 * IT WORKED! *Woohoo* 😀
 * Thank you alchymyth 🙂
 *  [Vogelpesto](https://wordpress.org/support/users/vogelpesto/)
 * (@vogelpesto)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230222)
 * Thank you alchymyth!
    Now how do I make those thumbs link to the original posts?
 *  [Vogelpesto](https://wordpress.org/support/users/vogelpesto/)
 * (@vogelpesto)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230223)
 * Nevermind, got it. Changed line 12 to
    `echo '<a href="' . get_permalink($header_thumb-
   >ID) . '">' . get_the_post_thumbnail($header_thumb->ID,array(240,170)) . '</a
   >';`
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230224)
 * well done – nice to see that an old topic is still useful 🙂

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

The topic ‘4 random thumbnails’ is closed to new replies.

## Tags

 * [display](https://wordpress.org/support/topic-tag/display/)
 * [images](https://wordpress.org/support/topic-tag/images/)
 * [thumbnails](https://wordpress.org/support/topic-tag/thumbnails/)
 * [thumbs](https://wordpress.org/support/topic-tag/thumbs/)

 * 12 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/4-random-thumbnails/#post-2230224)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
