• Resolved Drawer

    (@drawer)


    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?

    https://www.donnabarstow.com/WordPress

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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.

    Thread Starter Drawer

    (@drawer)

    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.

    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.

    Thread Starter Drawer

    (@drawer)

    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!

    Thread Starter Drawer

    (@drawer)

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

    #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.

    Thread Starter Drawer

    (@drawer)

    Very helpful, Moshu, thanks. I’ve copied it down to add to my “Important CSS” file!

    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. ??

    Thread Starter Drawer

    (@drawer)

    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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Alternating comments do not work’ is closed to new replies.