The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Alternating comments do not work (10 posts)

  1. Drawer
    Posted 9 years ago #

    I have just had to try to teach myself css in 2 weeks, to make changes in my theme, and this has been so frustrating.

    I am using WordPress Theme Generator for a theme. I can see that it has some css for something to do with alternating comments in the comment template, so I don't know why the comments don't alternate. Any suggestions, please?


  2. Jeremy Clark
    Posted 9 years ago #

    In your comments.php file there should be code that looks like this.

    /* This variable is for alternating comment background */
    		$oddcomment = 'alt';
    <!-- You can start editing here. -->
    <?php if ($comments) : ?>
    	<h3 id="comments"><?php comments_number('No comments filed', 'One comment', '% comments' );?> to “<?php the_title(); ?>”</h3> 
    	<ol class="commentlist">
    	<?php foreach ($comments as $comment) : ?>
    		<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
    			Comment by <em><?php comment_author_link() ?></em>:
    			<?php if ($comment->comment_approved == '0') : ?>
    			<em>Your comment is awaiting moderation.</em>
    			<?php endif; ?>
    			<br />
    			<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('l, F jS Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('Edit','',''); ?></small>
    			<?php comment_text() ?>
    	<?php /* Changes every other comment to a different class */	
    		if ('alt' == $oddcomment) $oddcomment = '';
    		else $oddcomment = 'alt';

    In your css make sure that the class for the alternating comments is named alt.

  3. Drawer
    Posted 9 years ago #

    Thanks, Jeremy, the code looks exactly as you wrote it, line for line (except the ends of your lines.). Still not alternating. Is there a place to put the colors of the alternating backgrounds that I should check on?
    Since I haven't started this yet, all the comments are me. But I don't think that should make a difference.

  4. Jeremy Clark
    Posted 9 years ago #

    Then look in your stylesheet for a class called alt it would look like this.


    Just apply a different background to that class. I also use a bottom border on it to separate the comments a little more.

  5. Drawer
    Posted 9 years ago #

    Jeremy, excellent, thanks!

    I see now that your last sentence after the php code mentioned the alt class, but I didn't understand what that meant. In fact, I didn't know that the paragraphs in css are called classes, until you just said it now. All it took was one sentence in css, for other people:
    .alt {background-color: #e6e3d7}


  6. Drawer
    Posted 9 years ago #

    PS, I wanted to add that there was NO alt class until I added in that one sentence.

  7. moshu
    Posted 9 years ago #

    #something = this is an ID
    .anothersomething = this a class
    (in the stylesheet)

    In your HTML markup they will look like:

    <div id="something">... </div>
    <div class="anothersomething"> ... </div>

    An "id" can occur only once per page, while classes can be used repeatedly.

  8. Drawer
    Posted 9 years ago #

    Very helpful, Moshu, thanks. I've copied it down to add to my "Important CSS" file!

  9. Root
    Posted 9 years ago #

    I would just observe that learning CSS in total might take more than 2 weeks. Don't be hard on yourself, for many of us it's been a lifelong challenge. And then some. :)

  10. Drawer
    Posted 9 years ago #

    Ah, Root, thanks so much! I haven't really "learned" it, I guess. I just kind of push and pull it, and try things out. And I've been very hard on myself, and impatient, and all sorts of bad things.
    I appreciate your kind comment.

Topic Closed

This topic has been closed to new replies.

About this Topic