WordPress.org

Ready to get started?Download WordPress

Forums

How to alternate color for every other post? (5 posts)

  1. ccheaton
    Member
    Posted 9 years ago #

    I'm trying to alter my index.php so that every other post calls a variation of the .post class from the .css file, thereby allowing me to give a different colored background to alternating posts (similar to how this forum does).
    So, I guess my question is this: is there a way to parse the ID number of the post, evaluate whether it is odd or even, and then call the .post class (say, .post1 or .post2) based on the results of the ID evaluation?
    I think that I would need a PHP function that returns text of either <div class="post1"> or <div class="post2"> based on the results.
    Thanks!

  2. ig0tch4
    Member
    Posted 9 years ago #

    maybe you could do it with a little javascript http://www.alistapart.com/articles/zebratables/

  3. ccheaton
    Member
    Posted 9 years ago #

    Fantastic. This is exactly what I was looking for, despite the fact that I failed to find it by searching. D'oh! Thanks for pointing it out to me. It's now functioning as it should.
    I appreciate the help.

  4. Beel
    Member
    Posted 9 years ago #

    Not bad, glad you got it working. Of course, it might be better to have something like the variable as an ID or class and set the values in the css. That will make it more consistent and you can change more than just the bg color.

  5. ccheaton
    Member
    Posted 9 years ago #

    Ok, I migrated some stuff around on my server to replace my mockup with the wordpress version, just so that people reading this thread will know. Now, if you visit http://www.publichealthcenter.com you will get the WP version, and no longer the design mockup. So, the links above may no longer bring up sites...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.