I’m still learning php, but can’t get my head on this one.
For a loop in WordPress I want to output a list with places, seperated with a comma and ending with a point.
Here’s my code:
<?php if ( have_rows('subplaats') ): ?>
<section id="subplaats">
<div class="subplaats-container">
<h3 class="support">Wij bestrijden ook in...</h3>
<p>
<?php while( have_rows('subplaats') ): the_row(); ?>
<?php $plaats = get_sub_field('plaats'); ?>
<?php echo $plaats; ?>,
<?php endwhile; ?>
</p>
</div>
</section>
<?php endif; ?>
Could anyone tell me how to accomplish this? I’m using Advanced Custom Fields. Am I also doing right on hierarchical level?
You need to count the total fields in the repeater:
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:
Cheers!