Support

Account

Home Forums General Issues Repeater field dumping into tables Reply To: Repeater field dumping into tables

  • I wasn’t exactly sure what $totalNum is used for but this is an example that will add the class every other row, starting with the second

    
    <table>
      <tbody>
        <tr>
          <th>Cookie Flavors</th>
        </tr>
        <?php 
          if (get_field('flavors')) {
            $index = 1;
            while (has_sub_field('flavors')) {
              ?>
                <tr<?php 
                       if ($index % 2 != 0) {
                        ?> class="bg"<?php 
                      }
                    ?> class="bg">
                  <td><?php the_sub_field('flavor'); ?></td>
                </tr>
              <?php 
              $index++;
            } // end while
          } // end if
        ?>
      </tbody>
    </table>