Skip to main content
deleted 62 characters in body
Source Link
Wyck
  • 18k
  • 4
  • 46
  • 67

This is the function I use, maybe there is a better way.

$attachments = get_children(
                            array(
                                  'numberposts' => -1,
                                  'order'=> 'ASC',
                                  'post_mime_type' => 'image',
                                  'post_parent' => get_the_ID(),
                                  'post_status' => null,
                                  'post_type' => 'attachment'
                                  ));

               $first_attachment = reset($attachments);
               //$last_attachment  = end($attachments); or last image
               echo wp_get_attachment_image($first_attachment->ID, 'full');

Additional wp_get_attachment_image parameters found here: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

This is the function I use, maybe there is a better way.

$attachments = get_children(
                            array(
                                  'numberposts' => -1,
                                  'order'=> 'ASC',
                                  'post_mime_type' => 'image',
                                  'post_parent' => get_the_ID(),
                                  'post_status' => null,
                                  'post_type' => 'attachment'
                                  ));

               $first_attachment = reset($attachments);
               //$last_attachment  = end($attachments); or last image
               echo wp_get_attachment_image($first_attachment->ID, 'full');

Additional wp_get_attachment_image parameters found here: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

This is the function I use, maybe there is a better way.

$attachments = get_children(
                            array(
                                  'numberposts' => -1,
                                  'order'=> 'ASC',
                                  'post_mime_type' => 'image',
                                  'post_parent' => get_the_ID(),
                                  'post_type' => 'attachment'
                                  ));

               $first_attachment = reset($attachments);
               //$last_attachment  = end($attachments); or last image
               echo wp_get_attachment_image($first_attachment->ID, 'full');

Additional wp_get_attachment_image parameters found here: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

Source Link
Wyck
  • 18k
  • 4
  • 46
  • 67

This is the function I use, maybe there is a better way.

$attachments = get_children(
                            array(
                                  'numberposts' => -1,
                                  'order'=> 'ASC',
                                  'post_mime_type' => 'image',
                                  'post_parent' => get_the_ID(),
                                  'post_status' => null,
                                  'post_type' => 'attachment'
                                  ));

               $first_attachment = reset($attachments);
               //$last_attachment  = end($attachments); or last image
               echo wp_get_attachment_image($first_attachment->ID, 'full');

Additional wp_get_attachment_image parameters found here: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image