I am building a template where wordpress is being used primarily as an image CMS, I am pulling the first image from the content section of each post.
<img src="<?php echo grab_image() ?>" />
function grab_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
$first_img = "";
}
return $first_img;
}
My question is how can I, instead of grabbing it from post_content, grab the first image from the uploaded image gallery?
So, the process to add an image would be to upload and then exit out (without inserting into post). I dont know what you call this or what to look for.. attachments? media library? The content area would be used strictly for text along with any extra meta boxes.