I am grabbing an image that is uploaded to that post working with this function:
wp_get_attachment_image_src
<?php
$images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 2 ) );
if ( $images ) :
$total_images = count( $images );
$image = array_shift( $images );
$image_img_tag = wp_get_attachment_image_src( $image->ID, 'full' );
?>
<div class="two_images">
<img src="<?php echo $image_img_tag[0] ?>">
</div>
How do I grab the first two images that are uploaded to a post? I guess I need help with a foreach statement.. and limit it to two. I tried this but it just printed the same first image over and over..
<?php foreach ($image as $images) {
echo "<img src='$image_img_tag[0]'>";
} ?>
IF I echo $total_images
then I get the correct count of 2
Looks like you may have just not had a loop setup, try this one