I have setup a custom Post Type in WordPress and have a question. How can I have WordPress assign the last item in my query a different class?
Here is my code: (This works perfect…)
<?php
$args = array('post_type' => 'testimonial_quote', 'posts_per_page' => -1);
// The Query
$the_query = new WP_Query( $args );
// The Loop
$i = 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="quote-main">
<p class="quote"><?php echo get_field('testimonial_item'); ?></p>
<p class="name"><?php echo get_field('testimonial_name_item'); ?></p>
<p class="company"><?php the_title(); ?></p>
</div>
<?php
$i++;
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
For the last item in my list — I need it to be:
<div class="quote-main-final">
<p class="quote"><?php echo get_field('testimonial_item'); ?></p>
<p class="name"><?php echo get_field('testimonial_name_item'); ?></p>
<p class="company"><?php the_title(); ?></p>
</div>
(Basically changing the class name of “quote-main” to “quote-main-final” for the final item that it pulls)
Any help would be appreciated.
You can count your results