WordPress.org

Forums

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

  1. cdeldridge
    Member
    Posted 4 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 4 years ago #

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

    http://www.transformationpowertools.com/wordpress/alternating-post-backgrounds-twentyten

  3. Shayne Sanderson
    Member
    Posted 4 years ago #

  4. cdeldridge
    Member
    Posted 4 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:

    ul>
    <?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"';} ?></
    ul

    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. alchymyth
    Forum Moderator
    Posted 4 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.

    a:
    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.

    b:
    imho, twenty ten already has alternating css classes at the comments:
    .even
    .odd
    .thread-odd
    .thread-even

    btw:
    http://www.rvoodoo.com/projects/wordpress/wordpress-tip-stop-editing-twentyten-theme-use-a-child-theme/

Topic Closed

This topic has been closed to new replies.

About this Topic