Does anyone know how I can display 4 random thumbnails from post images.
I want to display these thumbnails in my heading.
Does anyone know how I can display 4 random thumbnails from post images.
I want to display these thumbnails in my heading.
And no one knows? :(
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
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?
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.
With featured image assigned?
where else would your thumbnail come from?
Sorry. Missunderstood. I have posts with the featured image assigned.
here is a re-written version, using different wordpress codes:
IT WORKED! *Woohoo* :D
Thank you alchymyth :)
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 :-)
You must log in to post.