Hey guys/girls.
I'm using the following code to loop through the images attached to a page, and display the large sized images that WordPress creates. I want to link the large images to the full-size images, for Thickbox usage. How do I do this?
Here's my code:
'ASC',
'orderby' => 'menu_order',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => -1,
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) { ?>
ID, 'large', false, false);
}
}
?>
Solution - 1
Change:
echo wp_get_attachment_image($attachment->ID, 'large', false, false);
To:
echo ' ';
Solution - 2
Not familiar with Thickbox, but if you want to add a href around the image:
The new loop would be:
foreach ( $attachments as $attachment ) {
$full_image = wp_get_attachment_image_src( $attachment->ID, 'full', false, false );
list ( $full_src, $full_width, $full_height ) = $full_image;
echo '';
echo wp_get_attachment_image( $attachment->ID, 'large', false, false) );
echo '';
}
Ok, that's what you get when you answer and code at the same, almost the same answer was posted already,
With my version you keep the alt, title, width, height attributes of the image.
Solution - 3
//Put images from post in to array $images. Order by menu order defined in post gallery
$images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
if (isset($images)) {
$count=0;
//go through all images in array $images
foreach( $images as $image ) {
$imageID = $image->ID;
$medImageSrc = wp_get_attachment_image_src($imageID, $size='large', $icon = false);
$largeImageSrc = wp_get_attachment_image_src($imageID, $size='full', $icon = false);
echo" ";
$count++;
} //foreach
}
this will display:
It's really clean and easy to manipulate. Hope it helps!
|