0
votes

I have a slice of code:

<?php
if( have_rows('our_people') ):
$i = 0;
while ( have_rows('our_people') ) : the_row(); ?>
    <?php $i++; ?>
    <?php if( $i > 3 ):
        break; ?>
    <?php endif; ?>

    <a class="people-thumb fancybox-inline" href="#fancybox-<?php echo $i;?>">
                <div class="people-thumb-image" style="width:172px;height:172px;overflow:hidden;background:transparent url(<?php the_sub_field('people_image'); ?>) no-repeat center center; background-size:cover;"></div>
                <div class="people-thumb-details">
                    <h3><?php the_sub_field('people_name_acf'); ?></h3>
                    <p><?php the_sub_field('people_title'); ?></p>
                </div>
    </a>

    <div class="peopleoverlay">
        <div id="fancybox-<?php echo $i;?>">
        <img src="<?php the_sub_field('people_image'); ?>" width="172" style="float:left;margin:0 10px 10px 0;"> <?php the_sub_field('people_details'); ?>
        </div>
    </div>

<?php endwhile;    

 else :

 endif;
?>

What this does it simply count the entries and then stop after 3 - works fine.

However, with the other rows in the repeater field (after 3) how do I get those to also display? Reasoning is these 3 are in a seperate styling div, and all other entries are placed in another div.

However, if I try to repeat this code, nothing shows. So I must need to reset this somehow? I want all repeater rows after 3 to show in a different section.

1

1 Answers

0
votes

It looks that your code specifically says not to display more than 3 results! Annotated below.

$i = 0; // Start a counter

while ( have_rows('our_people') ) : the_row(); ?>   // As long as there are posts to display
<?php $i++; ?>         // increment the counter
<?php if( $i > 3 ):    // if the counter is 4 or more...
    break; ?>              // don't execute the code below; jump out of the while loop.
<?php endif; ?>

That being said, remove $i = 0, and the following lines:

<?php $i++; ?>
<?php if( $i > 3 ):
    break; ?>
<?php endif; ?>

This will allow ACF to display all the people stored in that metafield.

However, if you'd like to add a different class to the 4th div and beyond, change the conditional, to remove the break statement, and to wrap the result in a div that identifies it.

<?php $i++; ?>
<?php if( $i > 3 ): ?>
    <div class="other-style">
<?php endif; ?>

Then, you'd have to close it at the end with another check.

...
<?php if( $i > 3 ): ?>
    </div> <!-- .other-style -->
<?php endif; ?>