PHP – WordPress – Get all Attached Images for a Post/Page.

The given PHP example helps you to get all images that are attached to a post or page in WordPress.

Code Example:

<?php
$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image') );
foreach ( $attachments as $attachment_id => $attachment ) {
	echo wp_get_attachment_image( $attachment_id, 'medium' );
}
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail