Title: One Post Loop
Last modified: August 18, 2016

---

# One Post Loop

 *  [Jon Dingman](https://wordpress.org/support/users/jdingman/)
 * (@jdingman)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/)
 * Does anyone know the code to setup a custom ‘first post’ for the loop? I want
   to be able to apply a class which is specific under style.css to my FIRST post
   only. Anyone have an idea how to do this?

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

 *  [navid](https://wordpress.org/support/users/navid/)
 * (@navid)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/#post-139846)
 * Set up a counter variable like $counter = 1; outside of the loop. Then, in the
   loop, do a if( $counter == 1 ) and add the class to the post. Remember, in CSS,
   you can give tags several classes.
 * For example:
    `<div id="post434" class="bigborder lightbackground">....</div>`
 * while you can do:
 * #post434 { … }
    .bigborder { … } .lightbackground { … }
 * I hope this helps.
 * Navid.
 *  Thread Starter [Jon Dingman](https://wordpress.org/support/users/jdingman/)
 * (@jdingman)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/#post-139935)
 * I setup a loop like that, but it’s still not working correctly. It shows up under
   every post, not just the single post. Any other ideas how to setup the single
   post loop?
 *  [clay](https://wordpress.org/support/users/clay/)
 * (@clay)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/#post-139936)
 * are you incrementing the counter at the end of the loop?
 *  [ringmaster](https://wordpress.org/support/users/ringmaster/)
 * (@ringmaster)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/#post-139937)
 * Change this line in your loop:
    `<div class="post">`
 * To this:
    `<div class="post<?php if(!is_single() && $post==$posts[0]) echo ' 
   firstpost';?>">`
 * Add the appropriate style rules to “.firstpost” in your theme’s stylesheet.
 *  Thread Starter [Jon Dingman](https://wordpress.org/support/users/jdingman/)
 * (@jdingman)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/#post-139938)
 * Ringermaster: Am I still including the $counter = 1; before that or just that
   single line of code by itself?
 *  [ringmaster](https://wordpress.org/support/users/ringmaster/)
 * (@ringmaster)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/#post-139948)
 * Just that one line. No counter.
 * The “if” statement checks to see if the current post is the first post among 
   all the posts it’s going to display. If it is and the post is not the only post(
   is_single()) then it adds the extra class name.
 *  Thread Starter [Jon Dingman](https://wordpress.org/support/users/jdingman/)
 * (@jdingman)
 * [21 years, 3 months ago](https://wordpress.org/support/topic/one-post-loop/#post-139964)
 * Perfect, I’m not sure why it wans’t working the first time. It seems to be working
   fine now. thank you for giving me that small piece of code. It seems that under
   1.5 it makes it so much easier than having to make a loop and figure out where
   to end the loop, etc, etc. It makes it quite easy with 1.5.
 * Thanks!
 *  [Orin](https://wordpress.org/support/users/orin/)
 * (@orin)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/one-post-loop/#post-140085)
 * This didn’t work for me the first time, although it does in fact work perfectly.
 * The problem is that php will set the category as ‘post’ _plus_ ‘ firstpost’, 
   and having the class ‘.post firstpost’ doesn’t work as the browser will be looking
   for a `<firstpost>` tag. So I changed it to this:
 * `<div class="post<?php if(!is_single() && $post==$posts[0]) echo '-first';?>"
   >`
 * Thus, the first post is ‘.post-first’ and every other post is just ‘.post’ .
 *  [TechGnome](https://wordpress.org/support/users/techgnome/)
 * (@techgnome)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/one-post-loop/#post-140086)
 * 1) It’s CLASS, not category.
    2) Having class =”post firstpost” is perfectly 
   valid. It will simply apply the post class CSS then apply the firstpost class
   CSS. I’ve seen it done before, and have even done it myself a few times. There’
   s nothing wrong with it.
 * Tg
 *  [Orin](https://wordpress.org/support/users/orin/)
 * (@orin)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/one-post-loop/#post-140088)
 * 1) You’re correct, wrong word.
    2) Ok, wasn’t quite clear on how this was supposed
   to work. The important part is it does. My modification is for those that want
   the classes independant of each other, which was my aim.
 * Thanks for clarifying this to everyone reading this thread.

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

The topic ‘One Post Loop’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 6 participants
 * Last reply from: [Orin](https://wordpress.org/support/users/orin/)
 * Last activity: [21 years, 1 month ago](https://wordpress.org/support/topic/one-post-loop/#post-140088)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
