How to alternate background colors for comments or posts in WordPress? (5 posts)

  1. cdeldridge
    Posted 5 years ago #

    I'm trying to change the background colors for comments in WordPress, but all of the tutorials I can find online are years old and don't seem to work for the newest version of WordPress, or at least I can't seem to figure them out with my lack of knowledge using PHP. Can anyone give me a brief walk-through of how to do this? I'm just using the standard Twenty Ten theme. Thanks in advance.

  2. Tara
    Volunteer Moderator
    Posted 5 years ago #

    Here is tutorial for alternating-post-backgrounds-twentyten. See if you can make it work for comments as well:


  3. Shayne Sanderson
    Posted 5 years ago #

  4. cdeldridge
    Posted 5 years ago #

    I followed the tutorial for the post backgrounds and nothing changes. Not sure what I'm doing wrong.

    As for the comments one I'm not sure where exactly I put this piece of code:

    <?php $i = 0; ?>
    <?php foreach ($comments as $comment) : ?>
    <?php $i++; ?>
    <li id="comment-<?php comment_ID() ?>"<?php if($i&1) { echo 'class="odd"';} else {echo 'class="even"';} ?></

    the < and > on the two "ul"s I removed so it would post.
    I've put it where one of the tutorials said to place it and it totally bricked my comments. Any suggestions?

  5. Michael
    Forum Moderator
    Posted 5 years ago #

    the < and > on the two "ul"s I removed so it would post.

    please use the code button instead of the b-quote to keep postes code readable.

    you might need to 'reload' the page in the browser to get changes to show (refresching the browser cache); or press 'ctrl' and 'f5' simultanously.

    imho, twenty ten already has alternating css classes at the comments:


Topic Closed

This topic has been closed to new replies.

About this Topic