WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Drawer
    Member
    Posted 6 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?

    http://www.donnabarstow.com/WordPress

  2. Jeremy Clark
    Moderator
    Posted 6 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() ?>
    
    		</li>
    
    	<?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
    Member
    Posted 6 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
    Moderator
    Posted 6 years ago #

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

    .alt{
    ...
    }

    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
    Member
    Posted 6 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}

    Thanks!

  6. Drawer
    Member
    Posted 6 years ago #

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

  7. moshu
    Member
    Posted 6 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
    Member
    Posted 6 years ago #

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

  9. Root
    Member
    Posted 6 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
    Member
    Posted 6 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