Posted By

RWolford on 11/24/10


Tagged

wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ZedVex
vehler


Get Post Thumbnail


 / Published in: PHP
 

Used in Wordpress to get the post Thumbnail. Thumb url goes to $img

  1. <?php
  2. //Get images attached to the post
  3. $args = array(
  4. 'post_type' => 'attachment',
  5. 'post_mime_type' => 'image',
  6. 'numberposts' => -1,
  7. 'order' => 'ASC',
  8. 'post_status' => null,
  9. 'post_parent' => $post->ID
  10. );
  11. $attachments = get_posts($args);
  12. if ($attachments) {
  13. foreach ($attachments as $attachment) {
  14. $img = wp_get_attachment_thumb_url( $attachment->ID );
  15. break;
  16. }
  17. //Display image
  18. }
  19. ?>

Report this snippet  

You need to login to post a comment.