Support

Account

Home Forums Add-ons Repeater Field Add a class on every third row

Solving

Add a class on every third row

  • I have a repeater field that is wrapped around a div tag. On every third row I want to add a class last within <div class=”one_third”>. How can I do this?

    <?php if( have_rows("tombstones") ): ?>
        						<?php while( have_rows("tombstones") ): the_row();
        						$image = get_sub_field('tombstone_image');
        						?>
    							<div class="one_third">
    							<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" title="<?php echo $image['title'] ?>" />
    							</div>
  • Hey Kawaisin,

    This should do the trick (untested):

    <?php
    if(have_rows("tombstones"))
    {
    	$tombstonescount = 0;
    	while( have_rows("tombstones") )
    	{
    		$tombstonescount++;
    		$class = '';
    		$image = get_sub_field('tombstone_image');
    		if(i % 3 == 0)
    		{
    			$class .= 'last';
    		}
    		?>
            <div class="one_third <?php echo $class;?>">
            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" title="<?php echo $image['title'] ?>" />
            </div>
            <?php
    	}
    }
    ?>
  • No that doesn’t seem to work.

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

The topic ‘Add a class on every third row’ is closed to new replies.