0

I am trying to have the first-called post to have a different CSS class than the second. However, the class for each post is the same regardless of how I write this code.

I either have all thumbnails with class="active" or no thumbnails with the class.

What I am trying to have is the first post with class="img-fluid mx-auto d-block active" and the second as class="img-fluid mx-auto d-block"

   <?php 
                 $first_post = $the_query->posts[0] ;
                 
                 while ( $the_query->have_posts() ) : $the_query->the_post();
                if ($first_post !== $the_query->posts[0]){ ?>
                   <?php the_post_thumbnail( 'small', ['class' => 'img-fluid mx-auto d-block', 'title' => 'Feature image']);   ?>
                   <div class="carousel-caption">
                    <h3 ><?php the_title();?></h3>
                    <p><?php the_excerpt();?></p>
                    </div>
                    </div>
                      <?php }
                      else{ the_post_thumbnail( 'small', ['class' => 'img-fluid mx-auto d-block active', 'title' => 'Feature image']); ?>
                   <div class="carousel-caption">
                    <h3 ><?php the_title();?></h3>
                    <p><?php the_excerpt();}?></p> 
                      
                      
                </div>
            <?php endwhile; ?>
symcbean
  • 47,736
  • 6
  • 59
  • 94

0 Answers0