Support

Account

Home Forums Add-ons Repeater Field Need to show two Sub Fields on each div

Solved

Need to show two Sub Fields on each div

  • Hey! This is what I need:

    <div class="row">
      <div class="medium-6 columns">
        ...
      </div>
      <div class="medium-6 columns">
        ...
      </div>
    </div>

    but it is showing all Sub Fields instead of two:

    <div class="row">
      <div class="medium-6 columns">
        ...
      </div>
      <div class="medium-6 columns">
        ...
      </div>
      <div class="medium-6 columns">
        ...
      </div>
      <div class="medium-6 columns">
        ...
      </div>
    </div>

    So far this is what I have:

    <?php if (have_rows('testimonials-int')) { $count = 0; ?>
      <div class="row">
    
          <?php while(have_rows('testimonials-int')) { 
            the_row();
    
            $image = get_sub_field('avatar-int');
            $content = get_sub_field('content-int');
            $name = get_sub_field('name-int');
    
            if ($count % 2 == 0) {
          ?>
        
          <?php } ?>
          <div class="medium-6 columns wrapper">
            <img src="<?php echo $image; ?>" alt="Testimonials" />
            <?php echo $content; ?>
            <span><?php echo $name; ?></span>
          </div>
          <?php $count++; } ?>
          
      </div>
    <?php } ?>

    Thanks in advanced!

  • 
    <?php 
      if (have_rows('testimonials-int')) { 
        $count = 0;
        ?>
          <div class="row">
            <?php 
              while(have_rows('testimonials-int')) { 
                $count++;
                if ($count > 2) {
                  break;
                }
                the_row();
        
                $image = get_sub_field('avatar-int');
                $content = get_sub_field('content-int');
                $name = get_sub_field('name-int');
        
                ?>
                  <div class="medium-6 columns wrapper">
                    <img src="<?php echo $image; ?>" alt="Testimonials" />
                    <?php echo $content; ?>
                    <span><?php echo $name; ?></span>
                  </div>
                <?php 
              }
            ?>
          </div>
        <?php 
      }
    ?>
    
  • Hi! Now, it is showing only two of severals. Thanks.

  • Misread your post, I thought you only wanted to show 2, not in each div. The question I have is, what if there’s more than 4?

  • Not a problem! In fact, I want to show all of them but in this way:

    <div class="row">
      <div class="medium-6 columns">
        ...
      </div>
      <div class="medium-6 columns">
        ...
      </div>
    </div>
    <div class="row">
      <div class="medium-6 columns">
        ...
      </div>
      <div class="medium-6 columns">
        ...
      </div>
    </div>
    <div class="row">
      <div class="medium-6 columns">
        ...
      </div>
      <div class="medium-6 columns">
        ...
      </div>
    </div>
    etc.....

    I’m using the Zurb Foundation framework. Throwing all of them in just one <div class="row"> is not a good practice because if a div is higher than the other can break the layout. Thanks and sorry for the misunderstanding, didn’t explain in detail.

  • 
    <?php 
      if (have_rows('testimonials-int')) { 
        $count = 0;
        ?>
          <!-- open the first row -->
          <div class="row">
            <?php 
              while(have_rows('testimonials-int')) {
                the_row();
                if ($count > 0 && ($count % 2 == 0)) {
                  // close row and open new row
                  ?>
                    </div>
                    <div class="row">
                  <?php
                }
        
                $image = get_sub_field('avatar-int');
                $content = get_sub_field('content-int');
                $name = get_sub_field('name-int');
        
                ?>
                  <div class="medium-6 columns">
                    <img src="<?php echo $image; ?>" alt="Testimonials" />
                    <?php echo $content; ?>
                    <span><?php echo $name; ?></span>
                  </div>
                <?php 
                $count++;
              }
            ?>
          </div><!-- close the last row -->
        <?php 
      }
    
  • Yoohoo! Works perfect now! Thank you very much!

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

You must be logged in to reply to this topic.