Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created February 15, 2012 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpsmith/1836901 to your computer and use it in GitHub Desktop.
Save wpsmith/1836901 to your computer and use it in GitHub Desktop.
Trying to add "last-post" class to the loop
$post_classes = get_post_class();
$odd_or_even = 'even';
$post_counter = 0;
$post_counter++;
$odd_or_even = ( 'odd' == $odd_or_even ) ? 'even' : 'odd';
$post_classes[] = ( $post_counter == count( $posts ) ) ? 'last-post' :$odd_or_even;
echo '<div class="' . implode( ' ', $post_classes ) . '">';
@chrismccoy
Copy link

could add say a last to every 4th post.

<div class="post<?php if (!((1+$wp_query->current_post) % 4)) echo ' last' ?>">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment