Show Images from Post or Page Attachments

Get all image attachments from a page or post. I usually use this to show a slideshow on a page.
I also put how to get the title of the attachment (but I commented it). You can customize how the image will show.

 

<?php
$argsThumb = array(
'order'          => 'ASC',
'post_type'      => 'attachment',
'post_parent'    => $post->ID,
'post_mime_type' => 'image',
'post_status'    => null
);
$attachments = get_posts($argsThumb);
if ($attachments) {
foreach ($attachments as $attachment) {
//echo apply_filters('the_title', $attachment->post_title);
echo '<img src="'.wp_get_attachment_url($attachment->ID, 'thumbnail', false, false).'" />';
}
}
?>

masood

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment