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/Function_Reference/get_the_post_thumbnail
Thread Starter
Sinopa
(@sinopa)
Thank you alchymyth, but that didn’t work. No thumbnails are shown 🙁
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/ – simply follow http://codex.wordpress.org/Forum_Welcome#Posting_Code )
a link to your site?
Thread Starter
Sinopa
(@sinopa)
With featured image assigned?
Here’s the link to the code at pastebin http://pastebin.com/VPbvmtku.
It’s the the code from “It smells like facebook” theme.
Thread Starter
Sinopa
(@sinopa)
Sorry. Missunderstood. I have posts with the featured image assigned.
here is a re-written version, using different wordpress codes:
http://pastebin.com/QfLCgaBn
Thank you alchymyth!
Now how do I make those thumbs link to the original posts?
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>';
well done – nice to see that an old topic is still useful 🙂