• Can anyone tell me if it’s possible and if so how to go about introducing an alternate background color for posts..

    Example would be on index page if there are 4 posts showing:

    Post 1 bg color white
    Post 2 bg color pink
    Post 3 bg color white
    Post 4 bg color pink

    I have seen this done for comments where every other comment has a different color background but haven’t seen it on posts. I’m currently searching the forum and google reading up on conditional statements. But I’m honestly lost so thought while I search I’d ask the board.

    Many thanks in advance!

Viewing 1 replies (of 1 total)
  • Before the loop starts (with while (have_posts)), put this:

    <?php $i = 1; ?>

    Somewhere in the loop, probably at the end (right before endwhile;), put this:

    <?php $i++; ?>

    Then you can assign posts numbered classes. You’ll need to figure out where to put this. e.g. if your theme wraps every post in something like this:

    <div class="post">
    ...
    </div>

    You would change that to this:

    <div class="post post_<?php echo $i; ?>">
    ...
    </div>

    Then just add some CSS to your stylesheet to finish the job, something like this:

    post_1{background:#f00;}
    post_2{background:#00f;}
    etc....
Viewing 1 replies (of 1 total)
  • The topic ‘Alt Class For Posts?’ is closed to new replies.