Apply CSS class to every second database record

I have a class called “switchable” which basically switches the text and image from left to right, to right to left. I want this to happen for every second record. So, the first one on the left, and the second on the right etc. I just don’t know how to achieve this with the below code. Every second record should have instead of just ,

<?php $the_query = new WP_Query( array ( ‘post_type’ => ‘crew_members’, ‘order_by’ => ‘menu_order’, ‘order’ => ‘ASC’ ) ); ?>

<?php if( $the_query->have_posts() ): while ( $the_query->have_posts() ) : $the_query->the_post() ; ?>

<section>
<div class=”container”>
<div class=”row justify-content-between”>
<div class=”col-md-6″>
<div> <?php the_content(); ?> </div>
</div>
<div class=”col-md-6″>
<div class=”boxed boxed–lg boxed–border bg–secondary”> <?php the_post_thumbnail( array (475, 317), [ ‘class’ => ‘border–round’ ] ); ?>
<h5><?php the_title(); ?></h5>
<p> <?php the_field( ‘crew_member_excerpt’ ); ?> </p>
</div>
</div>
</div>
</div>
</section>

<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>

Read more here:: Apply CSS class to every second database record

Leave a Reply

Your email address will not be published. Required fields are marked *