Title: The loop , CSS and posts
Last modified: August 19, 2016

---

# The loop , CSS and posts

 *  [gambuto](https://wordpress.org/support/users/gambuto/)
 * (@gambuto)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/the-loop-css-and-posts/)
 * Hi there,
 * I have a problem with styling posts in a loop. I already read some topics on 
   the forum but they still didn’t solve my problem.
 * The issue is the following. I’m trying to make my posts line horizontal. CSS 
   wise I need my third post styled differently.
 * The thing is in this loop I have added code to exclude some categories so;
    On
   the website it shows 3 posts but my actual loop is 5 with 2 posts exluded. This
   way it makes it a real pain to target my third post for it could be the exluded
   one.
 * Any solutions to this problem because i cant find anything that can adress this
   problem
 * Thanks alot in advance,
    Gambuto

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

 *  [Michael Fields](https://wordpress.org/support/users/mfields/)
 * (@mfields)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/the-loop-css-and-posts/#post-1487815)
 * Something like this should work:
 *     ```
       <?php
       if ( have_posts() ) {
       	$post_count = 1;
       	while ( have_posts() ) {
       		the_post();
       		$class = ' class="post-count-' . $post_count . '"';
       		$post_count++;
   
       		print "\n\t" . '<div' . $class . '>';
       		the_title();
       		the_content();
       		print "\n\t" . '</div>';
       	}
       }
       ?>
       ```
   
 *  Thread Starter [gambuto](https://wordpress.org/support/users/gambuto/)
 * (@gambuto)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/the-loop-css-and-posts/#post-1488025)
 * You know what you are? A lifesaver 😀 thats what you are.
 * Worked like a charm just had to change the CSS a bit with the class you declared
   in the code.
 * Thx alot pro!!
 *  [Michael Fields](https://wordpress.org/support/users/mfields/)
 * (@mfields)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/the-loop-css-and-posts/#post-1488045)
 * gambuto,
    No problem! Glad it worked for you 🙂

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

The topic ‘The loop , CSS and posts’ is closed to new replies.

## Tags

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

 * 3 replies
 * 2 participants
 * Last reply from: [Michael Fields](https://wordpress.org/support/users/mfields/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/the-loop-css-and-posts/#post-1488045)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
