This is a simple question really but my novice php skills don’t extend this far. I have a repeater field and within that I have an image field. I’m trying to loop through each image object and get the url of the image and its title. I have also checked Image ID for ‘gimages’ in ACF. What am I doing wrong?
<?php
$img = the_sub_field('gimages');
if(get_field('image_gallery')): ?>
<?php while(has_sub_field('image_gallery')): ?>
<a href="<?php echo $img["url"] ?>" title="<?php echo $img["title"] ?>"><img src="<?php echo $img["sizes"]["thumb"] ?>" /></a>
<?php endwhile; ?>
<?php endif; ?>
Hi
I’m not sure what you code is doing, so forgive me if this is off key but I think you want something like this:
while( have_rows('repeater_field_name') ): the_row();
$attachment_id = get_sub_field('your image field'); $imageS = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
$imageF = wp_get_attachment_image_src( $attachment_id, 'full' );
?>
<a href="<?=imageF[0];?>"><img src="<?=imageS[0];?>"></a>
<?php
endwhile;
James
I’ve had to change accounts as ACF support wouldn’t allow me to login under my previous account. I tried the above code @rsrc1147 but it broke my page template so not sure what this is trying to do?
The issue isn’t getting the size of the image its displaying the full sized image and getting the title for that image. This is the most important thing for me right now.
Any pointers would be helpful