I am looking for a simple PHP function to insert the first image from the gallery into the post, full width (I am using custom post types btw). So the syntax will be:
<img src="xxxxx" />
any ideas?
many thanks Andy
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
gallery
shortcode.