• 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)
  • 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

    (@gambuto)

    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!!

    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.