Home › Forums › Add-ons › Repeater Field › Repeater, image field custom gallery
I am trying to make custom gallery with repetar field. Idea is basic, to have thumbnail of proper size and image in different hi res size. lets say that i want thumb 100×100 and hi res image to be 1024xXXXX.
Code i use is this one :
<?php if( have_rows('photo_thumbnails') ): ?>
<?php while( have_rows('photo_thumbnails') ): the_row();
$attachment_id = get_sub_field('gallery_image_10');
$size = "photoThumb"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
?>
<div class="col-md-3 col-sm-6">
<div class="item">
<div class="view view-first">
<img class="img-responsive" alt="" src="<?php echo $image[0]; ?>" />
<div class="mask-loupe wrapper-parent">
<a href="<?php the_sub_field('hi_res_image_10'); ?>" class="play-box" title="<?php the_sub_field('image_caption'); ?>">sve</a>
</div>
</div>
</div><!-- // item -->
</div>
<?php endwhile; ?>
<?php endif; ?>
But i dont like this approach for hi-res (blow up) image , because it does not resize it. It use even if i put 5000×5000 image and thats bad. So how can i make custom size for that part also? Since for thumbnail i use this
$attachment_id = get_sub_field('gallery_image_10');
$size = "photoThumb"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
<img class="img-responsive" alt="" src="<?php echo $image[0]; ?>" />
And that works perfect. But i want to use same stuff under
<a href="<?php the_sub_field('hi_res_image_10'); ?>" class="play-box" title="<?php the_sub_field('image_caption'); ?>">sve</a>
Thanks!
Hi @mitrovics
It seems you code is doesn’t doesn’t have the img tag and thus it doesn’t show any images.
If you want the anchor to link to the page, I would recommend that you test the image value to ensure that the image field returns a link and not an ID.
Hope this helps.
You must be logged in to reply to this topic.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.