You can use the variable $current_post
, something like this.
<?php
$query = new WP_Query(array(
'post_type' => 'custom_job',
'showposts' => 12
) );
?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php if ($query->current_post % 3 === 0) :?>
<?php $numbers = array('One', 'Two'); //add the rest ?>
<div class="jobs<?php echo $numbers[floor($query->current_post / 3)];?>">
<?php endif;?>
<div class="item">
<h2><a href="https://wordpress.stackexchange.com/questions/159913/<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<p><?php echo get_the_excerpt(); ?></p>
</div>
<?php if ($query->current_post % 3 === 0) :?>
</div>
<?php endif;?>
<?php endwhile; wp_reset_postdata();?>
You have to create an array for the CSS classname, I named it numbers
. The floor
function gets the lowest Integer given a Real.
This code isn’t tested, so be careful, don’t use it directly in production.