Home › Forums › Add-ons › Repeater Field › Even / Odd Display
I want to display every other row differently. On the odd numbered ones I want the image to display on the right and on the even rows I want the image to display on the left. Heres what I have currently that displays all the rows the same:
if( have_rows('magazines') ): ?>
<? while( have_rows('magazines') ): the_row();
// vars
$name = get_sub_field('magazine_name');
$image = get_sub_field('magazine_image');
$content = get_sub_field('magazine_description');
$link = get_sub_field('magazine_link');
$background = get_sub_field('magazine_background');
?>
<div class="fullscreen background parallax" style="background-image:url('<?php echo $background['url']; ?>');" data-img-width="1600" data-img-height="1064" data-diff="100">
<div class="content-a">
<div class="content-b">
<div class="wrap">
<div class="two-thirds first">
<h1><?php echo $name;?></h1>
<p><?php echo $content;?></p>
<a class="button" href="<?php echo $link;?>">View Magazine</a>
</div>
<div class="one-third">
<img data-name="image" src="<?php echo $image[url];?>" class="magazine-cover" alt="">
</div>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif;
Hi @chriswathen
You can use the get_row_index() function to check the current row. It should be something like this:
while( have_rows('magazines') ): the_row();
if( get_row_index() % 2 == 0 ){
// this is an even row
// code to display the image on the left
} else{
// this is an odd row
// code to display the image on the right
}
endwhile;
I hope this helps 🙂
Thank you very much, this is exactly what I was looking for.
The topic ‘Even / Odd Display’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.