I’d like to be able to choose one of those 6 images that I’d like to display as a large image within the same template file.
This would probably fit as the Post Thumbnail/Post Featured Image.
Additionally, out of these 6 images I’d like to randomly call in 1 random one on to a custom page template in another loop elsewhere on the site.
Try using get_children()
with the 'orderby' => 'rand'
and 'numberposts' => 1
parameters.
Assuming you know how to get the ID of the post whose image attachments you want to display, as $post_id
:
$random_post_images = get_children( array(
'post_parent' => $post_id,
'post_mime_type' => 'image',
'post_type' => 'attachment'
'orderby' => 'rand',
'numberposts' => 1,
) );
This will return an array of one image, as an object:
$random_post_image_object = $random_post_images[0];
Now, you can output the image, using wp_get_attachment_image()
:
$random_post_image = wp_get_attachment_image( $random_post_image_object->ID, 'thumbnail' );