Hello,
Firstly, such a great plugin with great extensions.
I have created a gallery field using the gallery extension.
I can display the galleries on a custom page template with no problems using the code below:
<?php
$images = get_field( 'gallery' );
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<?php $image_large = wp_get_attachment_image_src($image['id'], 'large'); ?>
<?php $image_thb = wp_get_attachment_image_src($image['id'], 'thumbnail', $image['caption']); ?>
<a href="<?php echo $image_large[0]; ?>" rel="lightbox[gallery]">
<img src="<?php echo $image_thb[0]; ?>" class="attachment-thumbnail" />
</a>
<?php endforeach; ?>
<?php endif; ?>
Is there a way to display the images meta info such as title, caption and description on the front end of the site along with the image itself?
Any help much appreciated
Thanks
Hi @rikardo85
In a similar way that the ID can be found like this: $image[‘id’]
The title can be found like this: $image[‘title’]
To find out all the data you can use, just debug the variable like so:
<?php
echo '<pre>';
print_r($image);
echo '</pre>';
die;
?>
Thanks
E
That’s great thank you.
I am using the following solution after experimenting:
<?php
$images = get_field( 'gallery' );
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<?php $image_large = wp_get_attachment_image_src($image['id'], 'large'); ?>
<?php $image_thb = wp_get_attachment_image_src($image['id'], 'thumbnail', $image['caption']); ?>
<div class="eventGal">
<a href="<?php echo $image_large[0]; ?>" rel="lightbox[gallery]">
<img src="<?php echo $image_thb[0]; ?>" class="attachment-thumbnail" /></a>
<h3><?php echo $image['title'];?></h3>
<p><?php echo $image['caption']; ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
Thanks for your help