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

Viewing 4 replies - 1 through 4 (of 4 total)
  • maybe you could do it with a little javascript https://www.alistapart.com/articles/zebratables/

    Thread Starter ccheaton

    (@ccheaton)

    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.

    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.

    Thread Starter ccheaton

    (@ccheaton)

    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 https://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…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to alternate color for every other post?’ is closed to new replies.