I would like to target the last Item on a foreach loop and add there some class's. Is that possible?
This is my code:
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'art',
'cat' => '6',
'orderby' => 'name',
'order' => 'ASC',
'post_status' => 'publish'
);
$posts_array = get_posts( $args );
foreach($posts_array as $post) : setup_postdata($post);
if ( has_post_thumbnail() ) {
$title = str_replace(" ", " ", get_the_title());
$thumb = get_the_post_thumbnail($post->ID, 'exhibition-pre');
if (has_post_thumbnail()) { ?>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs">
<a href="<?php echo get_permalink() ?>">
<?php echo get_the_post_thumbnail($page->ID, 'art-thumb', array('class' => 'max-img ')); ?>
<div class="imgcont"><?php echo the_title();?></div>
</a>
</div>
<?php
}
}
endforeach; ?>
<?php wp_reset_postdata(); ?>
I would like to have in the end:
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs CLEAR-Tablet>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs CLEAR-Screen>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs CLEAR-Tablet>...</div>
<div class="grid-3 grid-tablet-4 grid-mobile-6 artythumbs CLEAR-Screen>...</div>
and so on.