I am trying to add class first
to the first div of a row and class last
to the last div of a row. The number of divs in a row is user selectable and stored in a variable. the total number of divs is also user selectable and stored in a variable.
Here's what I have tried, but it adds the class only to the first row and not repeating for the rest.
$number_of_cols = 4; //User Selectable
$posts_per_page = 16; //User Selectable
$mas_query = new WP_Query( $args );
if ( $mas_query->have_posts() ) :
$count = 0;
while ( $mas_query->have_posts() ) : $mas_query->the_post();
$count++; ?>
<div class="blog-masonry-grid-items masonry-col-<?php echo $number_of_cols; echo ( $count == 1 || $count == $number_of_cols + 1 ? ' masonry-col-first' : ''); echo ( $count == $number_of_cols ? ' masonry-col-last' : '');?>">
<div class="grid-item-image-wrap"><?php if ( has_post_thumbnail() ) { the_post_thumbnail('medium_large'); } ?></div>
<div class="grid-item-content-wrap"><?php the_title( '<h3 class="entry-title grid-entry-title">', '</h3>' );?></div>
</div>
<?php endwhile; endif; ?>
How do I make it repeat for all divs pragmatically?
Thanks