Changes in Comment Styling

April 10th, 2007 by Mark

A couple days ago, Ryan and John pointed out to me that they had some usability issues with the color of the links on my site when you hover over them. I had been making them white, but that was just too hard to read on the light background of the site, especially for on some displays.

In a nod to all of the help and advice John’s given me, I immediately set the a:hover style to “Sinosplice Green“, i.e., the background color of John’s site that he’s been using since the bronze age of blogging. I was been busy with the school, and Google Docs had basically wreaked a gigantic curriculum document I’d been working on. There just wasn’t time to think about it. I just had to pick something that was readable. The only problem is that that particular color (#363) is ugly on this site. After giving my students a few new chapters in their textbook and getting their CDs burned yesterday, I finally had a little bit of time to turn my attention to fixing up my site a bit.

I ended up choosing just plain old blue for my link hover color. But, once I start fixing things, it’s hard to stop. As soon as I settled on blue for my links, I started getting irritated by other usability problems. For one, there were forty comments on my post about SEO. Most of them were from people, but a lot of comments were also just trackbacks from other people linking to the site. It was kind of hard for me to follow the discussion thread and read through them. In other words it was time to edit my comments.php and see what could be done.

Here’s what I came up with:

  1. Comments are now numbered.
  2. Comments made by me are now light blue, #eef, to be precise.
  3. I’m not quite sure what the difference between a trackback and a pingback is, but they’re pink, now.
  4. All other comments still alternate between normal (#eec) and lighter (#ffd) shades.

Now, it’s easy to tell refer to comments by number, it’s clear which of them are from the me and which are from guests, and it’s easy to skip over trackbacks and pingbacks while reading a thread. I’m pretty happy with it, but feedback and suggestions about the layout are more than welcome.

For those curious about how I did it, I’ve posted the code below:


All the changes I made were in the comments.php and my style.css files. Near the top of my comments.php, I created a variable to keep track of comment count, and one to hold the “type” of comment.

<?php $count = 0; ?>
$commenttype = 'alt';

I put them right before the line with

<?php if ($comments) : ?>

Then, right after the line with:

<?php foreach ($comments as $comment) : ?>

I added a counter and set a few more variables:

<?php $count++; ?>
<?php 
  $isByAuthor = false;
  if($comment->comment_author_email == 'me@somewhere.com') {
    $isByAuthor = true;
  }
?>
<?php
  $istback = false;
  if($comment->comment_type == 'trackback') {
    $istback = true;
  }
?>
<?php
  $ispingb = false;
  if($comment->comment_type == 'pingback') {
    $ispingb = true;
  }
?>

What that in place, it was very easy to set the class of each comment and print the comment number, using those variables. I put the following lines right after the block above:

<?php /* Changes  class based on type of comment */	
  if ($isByAuthor) $commenttype= 'authorcomment';
  else if ($istback) $commenttype= 'tbcomment';
  else if ($ispingb) $commenttype= 'pbcomment';
  else if ('alt' == $commenttype) $commenttype = '';
  else $commenttype = 'alt';
?>
		
<li class="<?php echo $commenttype; ?>" id="comment-< ?php comment_ID() ?>">
  <span class="count">
    < ?php echo $count; ?>
  </span>
  <cite>< ?php comment_author_link() ?></cite> Says:
...

After that, it was just a matter of adding styles to my style.css:

.alt {
   background-color: #ffd;
   border-top: 1px solid #ddd;
   border-bottom: 1px solid #ddd;
}

.authorcomment {
   background: #eef;
   border-top: 1px solid #ddd;
   border-bottom: 1px solid #ddd;
}

.pbcomment, .tbcomment {
   background: pink;
   border-top: 1px solid #ddd;
   border-bottom: 1px solid #ddd;
}

.count {
   float: right;
   margin: 10px 0px 10px 10px;
   font-size: 2em;
   color: #ddd;
}	
Tags: , , , , ,

11 Responses to “Changes in Comment Styling”

  1. 1 EFL Geek Says:

    For keeping colors looking good together since I have no inherent sense of fashion or design I use color schemer as it will show you which colors are complimentary. There are other tools available that do the same thing but I use this one.

  2. 2 range Says:

    Hey Mark, good improvements.

    The only thing I would say is to distinguish the links from the rest of the text. I can see a difference, the color of the links reminds me of your background color (a sort of dark blue), but they can easily missed.

  3. 3 Mark Says:

    Range, you mean the unvisited links in my entries, right? Right now, they’re #347, and the background, and the background is #333. I can see how that would be a bit easy to miss. I’ll have to think about what color would fit. The schemer suggested #7171d0. It looks alright, though a bit fluffy.

    EFL Geek, the color schemer’s a geek tool if I’ve ever seen one. I wonder how it works.

  4. 4 range Says:

    Yep those are the ones!

  5. 5 Tom Says:

    I didn’t even notice the numbers until you mentioned them. Maybe they should be black?

  6. 6 Mark Says:

    Tom, originally I thought about black. The reason I decided against it is that I thought it was too intrusive. I don’t want people to notice the numbers unless it’s a post with a lot of comments and they’re reading through it fairly careful. They stick out on trackbacks, but I’m hoping they’re as unobtrusive as possible.

    Range, I’ve tried a couple dozen colors… still looking.

  7. 7 range Says:

    Yeah, I can understand that!

    I used to do a lot of graphic design and coming up with the right colors can be a challenge sometimes.

  8. 8 pml Says:

    Hello! I found your site at random, while doing search for teaching English in Taiwan. My sister and I are both ABC (american-born Chinesee), can speak/read fluent Mandarin she moved to Taiwan, and assumed it would be so easy to snap up a teaching job. Instead, she experienced lots of reverse racism! But she ended up with a great job as a drug store manager- not anything she ever imagined being able to do.
    Anyway, just wanted to give my support. You have a great site going. Jia you!

  9. 9 range Says:

    Reverse racism! I’m not surprised. It’s good to get some testimony about it though.

  10. 10 Sadil Says:

    Hi there. :) I know this is quite an old entry, but I wished to comment to thank you for this anyhow. I was looking for a way to make my own comments in a different style class and this helped out immensely! So thank you for your contribution!

  11. 11 fstorr Says:

    Thanks - this worked a treat. Just a note for any Wordpress users looking to this on a multi-author blog, you can replace the me@somewhere.com bit with the get_the_author_email() function.

Leave a Reply

Quicktags: