Title: Get odd / even posts
Last modified: August 19, 2016

---

# Get odd / even posts

 *  [threevisual](https://wordpress.org/support/users/threevisual/)
 * (@threevisual)
 * [16 years ago](https://wordpress.org/support/topic/get-odd-even-posts/)
 * Hey, I’m working on a new theme, it has two columns.
 * In column 1 i want to list 5 even posts, in column two i’d like to have 5 odd
   posts.
 * Does anyone know how I could do this?
 * Thanks!

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

 *  [the-worlds-greatest-blogger](https://wordpress.org/support/users/the-worlds-greatest-blogger/)
 * (@the-worlds-greatest-blogger)
 * [16 years ago](https://wordpress.org/support/topic/get-odd-even-posts/#post-1493662)
 * My best guess would be define even as a multiple of two… Then on the odd post
   if even = false then show the post.
 *  Thread Starter [threevisual](https://wordpress.org/support/users/threevisual/)
 * (@threevisual)
 * [16 years ago](https://wordpress.org/support/topic/get-odd-even-posts/#post-1493665)
 * thanks for the comment, sadly I have no idea how to put that into code (I can
   just about code wordpress templates but not php).
 * at the moment i’m using this for the first column:
 * `<?php global $post; $myposts = get_posts('numberposts=5'); foreach($myposts 
   as $post) : setup_postdata($post);?>`
 * I just need to adapt it so it shows even / odd posts.
 *  Thread Starter [threevisual](https://wordpress.org/support/users/threevisual/)
 * (@threevisual)
 * [16 years ago](https://wordpress.org/support/topic/get-odd-even-posts/#post-1493841)
 * anyone have an idea of how I could get this to work?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years ago](https://wordpress.org/support/topic/get-odd-even-posts/#post-1493844)
 * how do you define an odd post?
 * this might work (untested):
 *     ```
       <?php
       global $post; $myposts = get_posts('numberposts=10');
       ?>
       <div class="column-odd">
       <?php
       $i=1;
       foreach($myposts as $post) :
       if($i%2 != 0) :
       setup_postdata($post);
       //output odd post in the usual way
       endif;
       $i++;
       endforeach;
       ?>
       </div>
       <div class="column-even">
       <?php
       $i=1;
       foreach($myposts as $post) :
       if($i%2 == 0) :
       setup_postdata($post);
       //output even post in the usual way
       endif;
       $i++;
       endforeach;
       ?>
       </div>
       ```
   
 * styles:
 *     ```
       .column-odd{ float:left; width: 48%; }
       .column-even { float:left; width: 48%; }
       ```
   
 *  Thread Starter [threevisual](https://wordpress.org/support/users/threevisual/)
 * (@threevisual)
 * [16 years ago](https://wordpress.org/support/topic/get-odd-even-posts/#post-1493847)
 * Worked like a charm. Thanks!

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

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

## Tags

 * [even](https://wordpress.org/support/topic-tag/even/)
 * [get posts](https://wordpress.org/support/topic-tag/get-posts/)
 * [odd](https://wordpress.org/support/topic-tag/odd/)
 * [question](https://wordpress.org/support/topic-tag/question/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [threevisual](https://wordpress.org/support/users/threevisual/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/get-odd-even-posts/#post-1493847)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
