Alternating Colors for Posts Hack

This hack was originally made for WP version 1.2. It works with 1.5 though the line numbers mentioned are a little different.

This is a derivative of the Alternating Colors for Comments change

In Index.php, add what’s in red in line 34 like so:
<?php if ($posts) :$i=0; foreach ($posts as $post) : start_wp(); ?>

Replace line 40:
<div class="post">
with the following:
<?php if($i%2) {echo "<div class="post-even">";} else {echo "<div class="post">";} $i++ ?>
To finish it off, add a class in wp-layout.css like so:
.post-even { background-color: #EEEEEE;}

And gosh darn it, I can’t figure out how to do proper code quoting. The entries
above do NOT display correctly. The double quotes inside the echos need to be
escaped with a slash just before them. Sorry I can’t display them properly in
Wordpress!
 

2 Comments

  1. roraz says:

    is this for version 1.5? I can’t seem to get it to work. I get error messages, I think for the first part of the change in index.php

  2. Rob says:

    Great, that even works in WP 2.0.

    Simple and elegant solution, thx for it.

Leave a Comment

Do not write "http://" or "https://" in your comment, it will be blocked. It may take a few days for me to manually approve your first comment.