Question

I need to add a "last" class to the last post that appears in loop.php.

Can someone tell me how to accomplish this?

Was it helpful?

Solution

assuming you're using post_class():

add_filter('post_class', function($classes){
  global $wp_query;

  if(($wp_query->current_post + 1) == $wp_query->post_count)
    $classes[] = 'last';

  return $classes;
});

OTHER TIPS

I am using jQuery addClass() when I style odd/even list items or similar. You could probably use it to achieve what you want too.

Example:

 $("#menu_side > ul > li:last-child").addClass("last");
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top