Posted By

trey on 02/23/09


Tagged

wordpress


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

mrbassman12
joelhaus
adambundy


Display the First Image Attachment of a WordPress Post


 / Published in: PHP
 

URL: http://wordpress.org/support/topic/165921

  1. <?php
  2. $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
  3. if ( ! is_array($attachments) ) continue;
  4. $count = count($attachments);
  5. $first_attachment = array_shift($attachments);
  6. ?>
  7. <?php echo wp_get_attachment_image($first_attachment->ID); ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: gabrielreloaded on April 25, 2010

Thank you!!

I've searched this code in many sites!!!

You need to login to post a comment.