Author comment highlighting troubles

Having seen, and liked, how some people have implemented author comment highlighting on their sites, I wanted to do the same here. So when first Dan Cederholm and then Judi Sohn recently posted articles explaining how they had done it, I thought I’d give it a go.

Noting that they both use MovableType, just like I do, I thought it would be easy peasy, and if one method didn’t work, the other would. Bzzt. Wrong.

I first tried Dan’s way: the Switch plugin. I edited my individual archive template to insert a class on each <dt> and <dd> in the comments list if the author is me. Upon checking the results I found that the plugin had given up halfway. The original code, adapted from Dan’s example, was this:

  1. <MTSwitch value="[MTCommentEmail]">
  2. <MTSwCase value=""> class="r"</MTSwCase>
  3. </MTSwitch>

What came out in the other end was this:

  1. class="r"</MTSwCase>
  2. </MTSwitch>

Anything after the first <MTSwCase> tag was printed literally. After spending some time trying to get it to work, I gave up on that method and moved on to the example provided by Judi. She uses a plugin called Compare, and the code looks like this:

  1. <MTIfEqual a="[MTCommentEmail]" b="">
  2. class="r"
  3. </MTIfEqual>

This almost worked for me. The plugin works fine if I manually enter values to compare, but I never managed to get [MTCommentAuthor] to match anything.

I don’t know if there is something wrong with my MT setup, or if I was just making some stupid, simple mistake, but either way I couldn’t get this to work. Anyone have similar problems trying to use either of these plugins? For the record, I’m still using Movable Type 2.65. I haven’t been convinced yet that an upgrade to 3.1 would be smooth enough.

I wasn’t ready to give up though, so I turned to PHP:

  1. <?php
  2. if ("<$MTCommentEmail$>" == "") {
  3. ?> class="r"<?php
  4. } ?>

Finally something that works, so now it’s a little easier to spot any comments made by me. The exact styling is subject to change over time. And no, I am not using those exact values to check if the author is me ;)

Posted on November 11, 2004 in Movable Type


  1. I suggest you use the email field instead, especially if you never show it on the site (which you shouldn’t!) This way, no one can “spoof” your identity.

    I succesfully use the Switch approach.

    <MTSwitch value=”[MTCommentEmail spam_protect=’0’]”> <MTSwCase value=””>class=”myComment”</MTSwCase> <MTSwDefault>class=”comment”</MTSwDefault> </MTSwitch>

  2. November 11, 2004 by Roger Johansson (Author comment)

    Right. That’s what I do, actually. I just used the author field as an example. I’ll edit the examples to use the email field instead.

    Your comment gave me a useful clue though: I did not use the spam_protect=”0” attribute for the MTCommentEmail field… so I guess that’s one reason I was never able to match against my address.

  3. I recently took the leap to MT3.1 and the upgrade was incredibly painless. The interface is a little better, especially for managing comments but surprisingly, not a huge difference between 2.6 and 3.1.

  4. I used the php version in your post and it works great and is easy to implement. Great article.

  5. November 12, 2004 by Andrew P Massey

    Not sure if this is why it all when pear in the first place, but comparing your code with Dan’s it appears you didn’t wrap the code in the <dt> tag: I might be way off here, so appologies.

    And, to be more pedantic, surely there should be a [space] between the <dt and the <MTSwitch (?)

  6. November 12, 2004 by Roger Johansson (Author comment)

    Andrew: I left the <dt> elements out of my examples to simplify them ;-).

    Nope, no space. When there is no match, no class should be written to the page, and we don’t want a space before the closing >.

  7. Using the email field also ensures uniqueness: whilst no two people can share email addresses, shared names are common.

  8. I like the design of your highlighting. It is smooth enough to not break the design while still standing out from the rest of the comments.

  9. November 24, 2004 by Roger Johansson (Author comment)

    Pete: Thanks :)

  10. I recently set out to do the same on my own blog (writeup:

    I think I experienced the same trouble with the Compare-approach. As far as I remember because of the placement of the compare; you might not have access to a required container-tag from where you’re trying to use your Compare…or something like that. It works for me in the exact way you’ve described above - doesn’t prevent sppofing, though - I’ll have to look into that later.

  11. I’m having problems getting my MT tags to be recognized inside of the PHP calls. For example, if I put dummy text strings (if ‘a’ == ‘a’) then it will return the correct value, but if I put in actual values (if (“<$MTCommentEmail$>” == “”)), then it always gives me false.

    I’ve tried spam_protect=”0”, but it still isn’t functioning right. Any ideas?

  12. January 6, 2005 by Roger Johansson (Author comment)

    Jason: Not really. I’m using the format described in the article, and it works. One thing I’d try is checking what the <$MTCommentEmail$> tag actually writes to the page in case it isn’t what you expect.

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.