• Resolved Vahid Nameni

    (@vahid216)


    Hello
    I want show random post with thumbnail and using this code :

    <?php
     $rand_posts = get_posts('numberposts=5&orderby=rand');
     foreach( $rand_posts as $post ) :
    
     ?>
    
    <a href="<?php the_permalink(); ?>">
            <?php the_post_thumbnail(array(150,130)); ?></a>

    But all thumb is the same and are from last post.
    And now i need to know the RIGHT code for showing thumbnails.
    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try using:

    <?php
    $rand_posts = get_posts('numberposts=5&orderby=rand');
    foreach( $rand_posts as $post ) :
    setup_postdata($post);
    ?>
    
    <a href="<?php the_permalink(); ?>">
    <?php the_post_thumbnail(array(150,130)); ?></a>
    Thread Starter Vahid Nameni

    (@vahid216)

    Thanks esmi its working nice.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Random posts with thumnlais’ is closed to new replies.