Don't like ads? PRO users don't see any ads ;-)
Guest

random thumbs

By: alchymyth on May 26th, 2012  |  syntax: PHP  |  size: 0.51 KB  |  hits: 70  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. //to show four random post thumbs
  3. $thumb_posts = new WP_Query(array(
  4. 'post_type' => 'post',
  5. 'ignore_sticky_posts' => 1,
  6. 'posts_per_page' => 4,
  7. 'meta_key' => '_thumbnail_id',
  8. 'orderby' => 'rand' ));
  9. if($thumb_posts->have_posts()) : ?>
  10. <div class="sub-post-thumbs">
  11. <?php while($thumb_posts->have_posts()): $thumb_posts->the_post();
  12. echo '<a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID,array(120,80)) . '</a>';
  13. endwhile; ?>
  14. </div>
  15. <?php endif;
  16. wp_reset_postdata();
  17. ?>