One thing I noticed when checking this site for bugs is that, even though I have my comments set up to alternate styles to differentiate one commenter from the next, MY comments didn’t stand out from everyone else’s comments. That just irked me. Why shouldn’t my comments stand out on my own blog? Confused

So, I poked around and played with the comment loop, and this is what I came up with.

Originally, my comment loop looked like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..........
<?php $oddcomment = 'class="alt" '; ?>
<?php if ($comments) : ?>
..........
<ol class="commentlist">
    <?php foreach ($comments as $comment) : ?>
<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
            <?php if(function_exists('get_avatar')){ echo get_avatar($comment, '30'); } ?>
                <cite><?php comment_author_link() ?></cite> Says:
                <?php if ($comment->comment_approved == '0') : ?>
                <em>Your comment is awaiting moderation.</em>
            <?php endif; ?>

            <small class="commentmetadata">
                <a href="#comment-<?php comment_ID() ?>" title="">
                <?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a>
                <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?>
            </small>
            <?php comment_text() ?>
        </li>

    <?php $oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : 'class="std" '; ?>
    <?php endforeach; ?>
    </ol>

..........

And with a a few modifications, it now looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..........
<?php $oddcomment = 'class="alt" '; ?>
<?php if ($comments) : ?>
..........
<ol class="commentlist">
    <?php foreach ($comments as $comment) : ?>
        <?php
            if ( $comment->comment_author_email !== get_the_author_email() ) {
                $oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : 'class="std" ';
            }
            else {
                $oddcomment = 'class="iwroteit" ';
            }
        ?>
<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
            <?php if(function_exists('get_avatar')){ echo get_avatar($comment, '30'); } ?>
                <cite><?php comment_author_link() ?></cite> Says:
                <?php if ($comment->comment_approved == '0') : ?>
                <em>Your comment is awaiting moderation.</em>
            <?php endif; ?>

            <small class="commentmetadata">
                <a href="#comment-<?php comment_ID() ?>" title="">
                <?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a>
                <?php edit_comment_link('edit','&nbsp;&nbsp;',''); ?>
            </small>
            <?php comment_text() ?>
        </li>

    <?php endforeach; ?>
    </ol>

..........

So, here’s the breakdown of what’s going on.

PHP sets the variable $oddcomment to class="alt"

The comment loops checks to see if there are comments, and if comment(s) exist, it starts the loop.

The comment loop then checks the email address of the commenter and compares it to the email address of the author of the post. If the email addresses don’t match, then $oddcomment is set to either class="alt" or class="std" so the comment styles will alternate. Then the comment is written to the page. However, if the email address of the commenter matches the email address of the author of the post, then $oddcomment is set to class="iwroteit" and the comment is written to the page.

The only things that need to be set are the three CSS classes that are defined as alt, std, and iwroteit. While I have alt and std set by default, the one class I had to define was iwroteit. I just changed the background and border colors to something that popped, which in my case was a snazzy green color, and now all of my comments and replies stand out on the page!