If you want to change the output of last item in loop (ACF) You need to count the total fields in the repeater:
1 | count(get_field('subplaats')); |
then have a field counter to check if the current “counted” field is the last one.
I edited and tested your code and It’s working good:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <?php if (have_rows('subplaats')): $all_fields_count = count(get_field('subplaats')); $fields_count = 1; ?> <section id="subplaats"> <div class="subplaats-container"> <h3 class="support">Wij bestrijden ook in...</h3> <p> <?php while (have_rows('subplaats')): the_row(); $plaats = get_sub_field('plaats'); echo $plaats; if ($fields_count == $all_fields_count) { echo "."; } else { echo ", "; } $fields_count++; endwhile; ?> </p> </div> </section> <?php endif; ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.