For Get the Images From Perticuler POST of Wordpress

How to Fetch a Images From Particular POST or Page of Wordpress.

Here the Code,


<?php
$thumb_ID = get_post_thumbnail_id( $post->ID );

if ( $images = get_posts(array(
'post_parent' => 1,
'post_type' => 'attachment',
'numberposts' => -1,
'orderby'        => 'title',
'order'           => 'ASC',
'post_mime_type' => 'image',
'height' => '200',
'exclude' => $thumb_ID,
)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image_src( $image->ID, full );
$imageDescription = apply_filters( 'the_description' , $image->post_content );
$imageTitle = apply_filters( 'the_title' , $image->post_title );

if (!empty($imageDescription)) {
   echo '<a href="'.$imageDescription .'"><img src="' . $attachmentimage[0] . '" alt=""  height=185 width=185/></a>';
} else { echo '<img src="' . $attachmentimage[0] . '" alt="" />'; }
}
} else {
echo "No Image";
}
echo '<br>';
?>



Where 'post_parent' => 1, is id of Page or Post wich images you want to display.
eg,
You want to display all the images from page id 115 , So you have to initialize the Parameter Like that.

'post_parent' => 115,

Comments