A loop in PHP means that what is inside is going to be repeated over and over.
So in your loop, what is inside is an image with a link back to my plugin page. Which isn’t a valid image link. That is what you are doing wrong. You need to use the $id inside the array, that is the ID of each image in the gallery.
Use that ID to get the image URL, and plug that into your <img> tag.
Hi, ok i understand, thanks for your answer.
Now I’ve tried it like this:
<?php $galleryArray = get_post_gallery_ids($post->ID); ?>
<?php foreach ($galleryArray as $id) {
<img src="<?php echo wp_get_attachment_url( $id ); ?>">
<?php } ?>
Still getting an error.
Okay; I’ve found the problem
<?php $galleryArray = get_post_gallery_ids($post->ID); ?>
<?php foreach ($galleryArray as $id) { ?>
<img src="<?php echo wp_get_attachment_url( $id ); ?>">
<?php } ?>
Now the images appear.
Is there a way to show only the first image and link it to a lightbox gallery?
I found one half working solution in you support forum:
Show featured gallery in fancybox
But this function is not recognized by wordpress:
$attachment_meta = wp_get_attachment( $id );
So I added this to my content-single.php
All the images in the gallery are displayed and linked.
<?php $galleryarray = get_post_gallery_ids($post->ID);
foreach ($galleryarray as $id) {
$imagesize = wp_get_attachment_image_src( $id, 'thumb' );
?>
<a href="<?php echo $imagesize[0]; ?>">
<img src="<?php echo wp_get_attachment_url( $id ); ?>"></a>
<?php } ?>
But the (Huge IT) lightbox shows one image twice.
I guess it has something to do with the
$attachment_meta = wp_get_attachment( $id );
wp_get_attachment_url Returns the full URL. wp_get_attachment_image_src Does gets the URL but lets you specify the size, rather than just the full size image.
You probably want a thumbnail size for the <img> tag, and the full size for the .
Thanks Andy, though I’m not a developer just a designer it works for me now. And I even learned a bit more PHP. Good work, good support.
I’m glad you got it working! 🙂