Support

Account

Home Forums Add-ons Repeater Field Repeater 3 div in a div

Solved

Repeater 3 div in a div

  • Hi all,

    I’ve been trying for a while to do with the repeater, a div that would contain 3 div and once that completed, repeat the group of div.

    I saw different topics about this and I tried to apply the advice already present in the forums.

    But after several tests, even if it seems to work, the first DIV is empty in the first group of 3. I use Bootstrap 4 for the css. Here is the code, and thanks in advance if someone sees the problem and can help me.

    <div class="card-deck">
    <?php 
    if (have_rows('team')) {
    	
    $count = 0;
    	
    while (have_rows('team')) {
    	
    $nom = get_sub_field('nom');
    $role = get_sub_field('role');
    $photo = get_sub_field('photo');
    $size = 'thumbnail';
    $thumb = $photo['sizes'][ $size ];
    	
    if ($count > 0 && ($count % 3 == 0)) {
    
    ?>
    </div>
    <div class="card-deck">
    <?php 
    }
    the_row();
    ?>
    <div class="card mx-auto d-block"> 
    <div class="card-body">
    <a href="<?php echo $photo['url']; ?>" title="<?php echo $photo['title']; ?>">
    <img class="card-img-top" src="<?php echo $thumb; ?>" alt="<?php echo $photo['alt']; ?>" /></a>
    	
    <p class="text-center">	
    <strong><?php echo $nom; ?></strong><br>
    <em><?php echo $role; ?></em>
    </p>
    </div>
    </div>
    <?php 
    $count++;
    }
    } else {
    }
    ?>
    </div>
  • Hi,

    your the_row need to be before you do any get_sub_field, so it starts the iteration. That’s why your first one is always empty because you haven’t start the iteration yet.

    So, a side note, you don’t need $count variable, acf has get_row_index() 😉

    Cheers.

  • Hi,
    Ok thank you for help. That was it.
    And, so, I see for get_row_index() and I will try with 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.