• Hi everyone, i want to show up 3 thumbnails by ID on site but have wrong with my code, this make only display 1 thumbnail instead of 3

    this code :

    <div class="gmenu">&raquo; Top Game Hay</div>
    <div class="appContainer" >
    <?php
    global $post;
    $myposts = get_posts(array('numberposts' => '3', 'orderby' => 'rand'));
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    <?php
    $thumb_id = get_post_thumbnail_id($post->ID);
    $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
    if(has_post_thumbnail())
    {
    echo '<div class="appPreview">';
    echo '<a href="'.get_post_meta($thumb_id, '_wp_attachment_image_alt', true).'">';
    echo get_the_post_thumbnail($post->ID ,'thumbnail', array( 'class' => 'appImg' ));
    echo '</a><div class="seller">';
    echo the_post_thumbnail_caption();echo '</div>';
    echo '<a class ="download" href="'.get_post_meta($thumb_id, '_wp_attachment_image_alt', true).'" rel="nofollow"> T?i V?</a>';
    echo '</div>';
    } ?>
    <?php endforeach; ?>
    <?php wp_reset_query(); ?>
    <div class="clearing"></div>
    </div>

Viewing 2 replies - 1 through 2 (of 2 total)
  • do all your posts have a featured image?

    if not, you could try to query only posts that have a featured image;

    change:
    $myposts = get_posts(array('numberposts' => '3', 'orderby' => 'rand'));

    to:
    $myposts = get_posts(array('numberposts' => '3', 'orderby' => 'rand', 'meta_key' => '_thumbnail_id'));

    Thread Starter huenguyenchrish

    (@huenguyenchrish)

    huraaa… finally I got it, thank you alchymyth It works perfect ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show thumbnails error’ is closed to new replies.