Forums

[resolved] 4 random thumbnails (13 posts)

  1. Sinopa
    Member
    Posted 9 months ago #

    Does anyone know how I can display 4 random thumbnails from post images.
    I want to display these thumbnails in my heading.

  2. Sinopa
    Member
    Posted 9 months ago #

    And no one knows? :(

  3. alchymyth
    The Sweeper
    Posted 9 months ago #

    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

  4. Sinopa
    Member
    Posted 9 months ago #

    Thank you alchymyth, but that didn't work. No thumbnails are shown :(

  5. alchymyth
    The Sweeper
    Posted 9 months ago #

    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?

  6. Sinopa
    Member
    Posted 9 months ago #

    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.

  7. alchymyth
    The Sweeper
    Posted 9 months ago #

    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

  8. Sinopa
    Member
    Posted 9 months ago #

    Sorry. Missunderstood. I have posts with the featured image assigned.

  9. alchymyth
    The Sweeper
    Posted 9 months ago #

    here is a re-written version, using different wordpress codes:

    http://pastebin.com/QfLCgaBn

  10. Sinopa
    Member
    Posted 9 months ago #

    IT WORKED! *Woohoo* :D

    Thank you alchymyth :)

  11. Vogelpesto
    Member
    Posted 4 months ago #

    Thank you alchymyth!
    Now how do I make those thumbs link to the original posts?

  12. Vogelpesto
    Member
    Posted 4 months ago #

    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>';

  13. alchymyth
    The Sweeper
    Posted 4 months ago #

    well done - nice to see that an old topic is still useful :-)

Reply

You must log in to post.

About this Topic