Support

Account

Home Forums Add-ons Flexible Content Field count get_row_layout to add odd / even class Reply To: count get_row_layout to add odd / even class

  • Because you have different types of layouts the solution would be to keep a running total of each type of layout.

    
    $layout_counts = array();
    
    // ... some time later
    
    while (have_rows('staff_content')) {
      the_row();
      $layout = get_row_layout();
      if (!isset($layout_counts[$layout])) {
        $layout_counts[$layout] = 0;
      }
      $layout_counts[$layout]++;
      $class = 'even';
      if ($layout_counts[$layout] % 2) {
        $class = 'odd';
      }
    
      //... some time later
    
      if ($layout == 'staff_member') {
        ?>
          <div class="staff <?php echo $class; ?>">
             /// etc...
          </div>
        <?php 
      }
    }