Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

Can someone tell me how to accomplish this?

share|improve this question
add comment

2 Answers

up vote 11 down vote accepted

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;
});
share|improve this answer
add comment

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");
share|improve this answer
    
Thanks for the response, but I'm not using jQuery. Also, using JavaScript to apply the class could cause the styling to display before the JavaScript loads, which would make it "flash off" and it wouldn't look pretty. –  user1462 Jan 20 '11 at 21:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.