Title: Recent posts even/odd classes
Last modified: August 20, 2016

---

# Recent posts even/odd classes

 *  [MLaugesen](https://wordpress.org/support/users/mlaugesen/)
 * (@mlaugesen)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/recent-posts-evenodd-classes/)
 * Hi experts,
 * I’ve searched around for this script but i can’t seem to quite figure out exactly
   how to do this. I need a script which shows the 5 recent post-titles, and within
   the script I want a li-class for the even and odd posts. Can anyone help me out?
   I need this for the 5 recent comments also.
 * Thank you
 * Martin

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [MLaugesen](https://wordpress.org/support/users/mlaugesen/)
 * (@mlaugesen)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/recent-posts-evenodd-classes/#post-3428146)
 * I have found this code:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post();?>
          <div class='<?php echo (++$j % 2 == 0) ? 'evenpost' : 'oddpost'; ?>'>
             <p><?php the_content(); ?></p>
          </div>
       <?php endwhile; endif; ?>
       ```
   
 * But this is within the loop, and that is not what I am looking for. I need the
   same 5 recent post-titles on every page.
 *  [Peter_L](https://wordpress.org/support/users/peter_l/)
 * (@peter_l)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/recent-posts-evenodd-classes/#post-3428147)
 * use get_posts
    [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Recent posts even/odd classes’ is closed to new replies.

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)
 * [even](https://wordpress.org/support/topic-tag/even/)
 * [odd](https://wordpress.org/support/topic-tag/odd/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Peter_L](https://wordpress.org/support/users/peter_l/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/recent-posts-evenodd-classes/#post-3428147)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
