Add Class to Last Post in Loop

Supplemental 47 views
0
0 Flares 0 Flares ×

Adds a class around the last post in a loop. Great for adding a border at the bottom of the last post, etc. etc.

<?php
	// Add a class to the last post in a loop
	// source: http://wpdaily.co/top-10-snippets/

function so_last_post_class($classes){
	global $wp_query;
	if(($wp_query->current_post+1) == $wp_query->post_count) $classes[] = 'last';
	return $classes;
}
add_filter('post_class', 'so_last_post_class');

For Reference:

Top 10 Snippets

Provided by: WP Daily
Tagged with:
Posted in Wordpress

Discuss:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.

Login

Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×