Add a second class to last post in loop
-
Hi,
I would like to add “last” to <article class=”post”> to be this <article class”post last”>
Here is what I have so far:
<?php $most_popular_query = new WP_Query( array( 'category_name' => 'player-news', 'posts_per_page' => 1 ) ); while ( $most_popular_query->have_posts() ) : $most_popular_query->the_post(); ?> <article class="post"> <div class="thumb"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'frontpage-most-popular-thumb' ); ?></a></div> <div class="cat"><?php the_category(', ') ?></div> <h3><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php echo(get_the_title()); ?></a></h3> <div class="activity"> <span class="views">12</span><span class="comment"><a href="#"><?php $comments_count = wp_count_comments(post_id);echo $comments_count->total_comments;?></a></span> </div> </article><!-- /.post --> <?php endwhile; // Reset Query wp_reset_query(); ?> <article class="post last"> <div class="thumb"> <a href="#"><img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/thumbs/7.jpg" alt="img"></a> </div> <div class="cat"> <a href="">Social media</a> </div> <h3><a href="#">I'm not claiming the multiplier is precisely 36, but it is certainly more than 10...</a></h3> <div class="activity"> <span class="views">12</span><span class="comment"><a href="#">0</a></span> </div> </article><!-- /.post -->I want to know how I can add a function inside my while loop to do this on the last post. Also, to make it easier, I don’t need the function to count current posts and determine which one is the last one. Essentially, there will be two posts in this loop, so I need to apply “last” to the class of the second post.
Thank you!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Add a second class to last post in loop’ is closed to new replies.