I have a function get_images()
in which I would like to display all image attachments for the current post (or page) in a list with the last image having a class="last"
attribute to mark it as the last image in the list.
The code below is my first pass at getting the attached images to display, however, its only listing one image out of the loop so my foreach is botched…
function get_images() {
global $post;
$attachment = array_values(get_children(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'numberposts' => 1
)));
if ( $attachment ) {
foreach($attachment as $attachmentImage) {
echo '<img src="' . wp_get_attachment_url($attachmentImage->ID) .
'" class="post-attachment" />';
}
}
}
This should do it, I think: