Title: Recent Posts Alternating
Last modified: August 19, 2016

---

# Recent Posts Alternating

 *  Resolved [death-dream](https://wordpress.org/support/users/death-dream/)
 * (@death-dream)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-alternating/)
 * I am creating a theme but in my side bar I want to have (for example) the top
   3 posts for my tutorials category to show up.
 * Check out [http://dd.adesadesmoines.com/](http://dd.adesadesmoines.com/) (not
   WPed theme, pure CSS/HTML at that time, outdated too)
 * On the right side you will see how the “latest tutorials” section has 3 parts,
   changing sides each time.
    `code` <div class=”detail” align=”left”> <img class
   =”iconL” src=”Images/TopIcons/UVmappingIco.gif”> <h3>UV Mapping</h3> <p class
   =”small”>Get the inside scoop on how to UV Map a head inside Maya.</p> </div>
 *  <div class=”detail” align=”right”>
    <img class=”iconR” src=”Images/TopIcons/
   UVmappingIco.gif”> <h3>UV Mapping</h3> <p class=”small”>Get the inside scoop 
   on how to UV Map a head inside Maya.</p> </div>
 *  <div class=”detail” align=”left”>
    <img class=”iconL” src=”Images/TopIcons/UVmappingIco.
   gif”> <h3>UV Mapping</h3> <p class=”small”>Get the inside scoop on how to UV 
   Map a head inside Maya.</p> </div> `/code`
 * So basically what I think I need is some code for each 3 sections.
    `code` <div
   class=”detail” align=”left”> <img class=”iconL” src=”php code to get Icon for
   category”> <h3>Php code to pull title for most recent post</h3> <p class=”small”
   >Post Discription</p> </div> <div class=”detail” align=”right”> <img class=”iconR”
   src=”php code to get Icon for category”> <h3>Php code to pull title for 2nd most
   recent post</h3> <p class=”small”>Post Discription</p> </div>`/code`
 * And so on … So what kind of code will allow me to pull the most recent posts 
   by number (if that makes sense) in that category.

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

 *  [equaldesign](https://wordpress.org/support/users/equaldesign/)
 * (@equaldesign)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-alternating/#post-854211)
 * To display the most recent posts from a category you can use this code:
 *     ```
       <?php $recent = new WP_Query("cat=1&showposts=3"); while($recent->have_posts()) : $recent->the_post();?>
       //do stuff!
       <?php endwhile; ?>
       ```
   
 * This will query the most recent 3 posts from category ID 1 – change the cat=1
   to whatever category you want to pull. So if you wanted to show the headings 
   from these posts then use this code:
 *     ```
       <?php $recent = new WP_Query("cat=1&showposts=3"); while($recent->have_posts()) : $recent->the_post();?>
       <h2><?php the_title(); ?></h2>
       <?php endwhile; ?>
       ```
   
 * Hope that helps.
 *  Thread Starter [death-dream](https://wordpress.org/support/users/death-dream/)
 * (@death-dream)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-alternating/#post-854222)
 * Yeah that helps. That would get the 3 recent posts. But the thing is, if I left
   it do the automatic query thing, it will want to aling everything on the left
   side. Thats why I want it to pull each post on its own. So say cat=1&showrececntpost1,
   cat=1&showrececntpost2, cat=1&showrececntpost3 (no idea on the code) So that 
   post2 could be pushed to the right that I placed inside the Div.
 * I hope that makes sense 🙂 Thanks for your help so far equaldesign.
 *  [equaldesign](https://wordpress.org/support/users/equaldesign/)
 * (@equaldesign)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-alternating/#post-854413)
 * I see. You can then use the offset function so that you can bring in the latest
   post offset by one do you would use this code for the first post:
 *     ```
       <?php $recent = new WP_Query("cat=1&showposts=3"); while($recent->have_posts()) : $recent->the_post();?>
       <h2><?php the_title(); ?></h2>
       <?php endwhile; ?>
       ```
   
 * this for the second:
 *     ```
       <?php $recent = new WP_Query("cat=1&showposts=3&offset=1"); while($recent->have_posts()) : $recent->the_post();?>
       <h2><?php the_title(); ?></h2>
       <?php endwhile; ?>
       ```
   
 * and this for the third post:
 *     ```
       <?php $recent = new WP_Query("cat=1&showposts=3&offset=2"); while($recent->have_posts()) : $recent->the_post();?>
       <h2><?php the_title(); ?></h2>
       <?php endwhile; ?>
       ```
   
 * This would then show the latest post from the top code, then the second to latest
   with the middle code and the last code would display the third to latest. That
   way you can style each of the areas as you wish.
 * Hope that makes sense.
 *  Thread Starter [death-dream](https://wordpress.org/support/users/death-dream/)
 * (@death-dream)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-alternating/#post-854418)
 * I love you equaldesign =D hahaha That did the trick!
 * I went ahead and change it to category names instead because it wasn’t pulling
   by the numbers which worked out great too.
 * “category_name=Tutorials&showposts=1&offset=2”
 * Thanks so much =D
 * ~Death Dream~

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

The topic ‘Recent Posts Alternating’ is closed to new replies.

## Tags

 * ["recent post"](https://wordpress.org/support/topic-tag/recent-post/)

 * 4 replies
 * 2 participants
 * Last reply from: [death-dream](https://wordpress.org/support/users/death-dream/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/recent-posts-alternating/#post-854418)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
