Get the latest image
-
Hi,
I’m using a code to get the latest image from a post. It works fine, except for the fact that if the next post dosen’t have an image, it shows the precious posts image insted. Any suggestions how to change that?
Here’s my code:
<?php $images = get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . get_the_id() ); foreach($images as $attachment_id => $attachment ) : ; $image = wp_get_attachment_image_src( $attachment_id, $size='medium'); endforeach; ?> <img src="<?php echo $image[0]; ?>" alt=""/>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Get the latest image’ is closed to new replies.