I am using the following to wrap every 3 divs, and wrap the the 4th-5 the same way if there is only 2. (same would apply it was every 6, 4, etc)
When its only 3 divs/elements they get wrapped as they should. But then an empty element gets created as well. So in the example below. Lets say you had 3 divs per list item. Well, in this one you only had 3, but an empty "list item" gets created containing nothing. How can I append my code so it doesn't create an empty element? (in my case, using the repeater with a flexslider, empty slide is being produced)
<?php //going to wrap every 3 in this example
if ( get_field( 'your_repeater_name' ) ): ?>
<?php $index = 1; ?>
<?php $totalNum = count( get_field('your_repeater_name') ); ?>
<li>
<?php while ( has_sub_field( 'your_repeater_name' ) ): ?>
<div class="col-sm-4">
<?php the_sub_field( 'your_sub_field' ); ?>
</div>
<? if ($index % 3 == 0) : ?>
<? if ($index < $totalNum) : ?>
// more rows, so close this one and start a new one
</li>
<row>
<? elseif ($index == $totalNum) : ?>
// last element so close row but don't start a new one
</li>
<? endif; ?>
<? endif; ?>
<?php $index++; ?>
<?php endwhile; ?>
<?php endif; ?>
Aucun commentaire:
Enregistrer un commentaire