Well, I was happily implementing a gallery using the ACF gallery field, when I noticed that as soon as I’d use the flexi content field’s row layout where this acf gallery field sits, more than 1 time per page, then my galleries were displaying all selected images in all of them.
I am somehow sitting on my brain today, so I am hoping that someone knows a solution to my problem here… :O
this is my row layout php code with the gallery foreach in it in a page template:
elseif( get_row_layout() == 'galeriesektion' ): $galerieUberschrift = get_sub_field('galerieuberschrift'); ?> <div class="teameventMain"> <div class="firmenGruppenBlock teameventContent"> <h3><span><?php echo $galerieUberschrift; ?></span></h3> </div> <?php $images = get_sub_field('slider'); if( $images ): $i = 1; echo '<div class="teameventImg"> <div class="fadeImgsBlock">'; foreach( $images as $image ): echo '<div class="fadeImgsOuter">'; echo '<figure class="fadeImgs"> <img src="'.$image['sizes']['bildlinkslanding'].'" alt="'.$image['alt'].'" width="645" height="414" /> </figure> <span class="imgNo">'.$i.'/'.count($images).'</span>'; $i++; echo '</div>'; // ende .fadeImgsOuter endforeach; // ende galerie echo '</div></div>'; // ende fadeImgsBlock und teameventImg endif; // ende if $images ?> </div> <!-- ende .teameventMain -->
This is the HTML output for a slider filled with the gallery images. It is js powered and addresses the element classes.
However when using two or more row layouts containing this gallery field with each different images loaded in them, I am still seeing all mushed up in every html output..
I hope this explanation makes sense to someone 😉
You code looks OK for me. Could you please share the URL where the code is used, the JSON export file of your field group and the complete template code? Please keep in mind that the forum attachment feature doesn’t allow you to upload a PHP file. Kindly zip it first or use https://gist.github.com/ instead.
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!
© 2023 Advanced Custom Fields.