Home › Forums › Front-end Issues › Outputting image title
Hi,
First of all, I would like to thank you for this great plugin, it’s really helpfull for WordPress development.
I have a problem that I can’t solve :
I have a subfiled named ‘photos’ in which I can add one or several images uploaded from WordPress.
I reach to display the image recovering the url (see the code below) but I can’t find a way to display the ‘title’ or ‘alt’ or ‘description’ of the image!!
Can you help me find the solution please ?
Here is my code :
<?php if(get_field('diaporama')){ ?>
<?php while(the_repeater_field('diaporama')): ?>
<img src="<?php the_sub_field('photos'); ?>"/>
<?php endwhile; ?>
<?php } ?>
Thanks in advance for your time.
P.S : sorry for my bad english, I’m from france 🙂
This will do it:
<?php
while(has_sub_field('diaporama')):
$image = get_sub_field('photos');
$image_full = $image['sizes']['large'];
$alt = $image['title']; ?>
<div class="col-split">
<a class="fancybox" rel="gallery1" href="<?php echo $image_full; ?>">
<img class="img_cen" src="<?php echo $image_thumb; ?>" alt="<?php echo $alt; ?>" title="<?php echo $alt; ?>" />
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
Hi rorymheaney,
Thanks for your help, this is almost what I need.
What you gave me works perfectly, but I can’t display full size image instead of large size image, even if I write that :
$image_full = $image[‘sizes’][‘full’];
Do you have an idea for that ?
Thanks again !
Thanks rorymheaney,
I just replaced the line :
$image_full = $image['sizes']['large'];
By
$image_full = $image['url'];
And now everything is ok.
Thanks for your help!
The topic ‘Outputting image title’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.