Author Highlighting in MT

I’ve finally implemented author highlighting for the comments here at SimpleBits. Any comment that I add myself gets a slightly different style treatment to set it apart from the rest. I first noticed Dave doing this quite awhile back. Many others followed — and I’ve found it pretty darn useful when I read other sites, being able to quickly scan for the site owner’s remarks.

How is it done? Depending on the system you’re using, there are approximately 34,760 ways to make this happen, and I came up empty when searching for a writeup on how people handle the swap. Here’s how I tackled it.

I started by downloading the Switch plugin for MT. This allows for conditional statements within Movable Type’s templates. I’m sure there are other methods — and feel free to leave your own tips in the comments.

Once the plugin was installed, I just needed a way to insert a class to the <dt> and <dd> elements that I use to structure the author and text for each comment. This class would only exist if the comment was authored by me.

Using the Switch plugin’s syntax I added this to the entry template:

<dt<MTSwitch value="[MTCommentAuthor]">
  <MTSwCase value="Dan Cederholm"> class="dan"</MTSwCase>

So here, I’m testing for when the author’s value is “Dan Cederholm”. If it is, then it’ll add whatever’s between the <MTSwCase> tags — in this case: class="dan". Notice the space before class — this is important, as for every other case but “Dan Cederholm”, we’ll just have a normal <dt> (or <dd>) element, without extra spaces.

With a class now inserted for my own comments, I could just add specific styles for dt.dan and dd.dan to make them unique.

While I’m using the value of MTCommentAuthor, the plugin will accept any MT tag to match against. You could use an email address, URL, etc. — or I suppose get even more fancy with IP address or other more secure methods. I do realize that, now that I’ve documented this, I’m making it easy for people to pretend to be Dan Cederholm (I’m not sure why one would want to do that), but simplicity is bliss.


  1. Josh says:

    I wish I could figure out how to install MT. WordPress was easier for me.

  2. Dave S. says:

    The easiest way to make it more secure for yourself is to rely on the email field, which is never (theoretically) public-facing, and then just match a password instead of your email address.
    Use the email field as the password entry field when you post a comment, and bingo, we’ll all be pretty darn sure that no one’s impersonating you on your own site.

  3. Dave – Brilliant. Thanks for sharing this. And yes, this is really me.

  4. Will says:

    Hey Dan, that’s cool. I’ll have to do that on my upcoming website.

  5. Rob Mientjes says:

    Of course, it’s no life saying it’s really you everytime :P
    Dave, that password tip is really useful.

  6. eric says:

    Nice subtle effect to highlight it, too. Looks good.

  7. Jeff says:

    Looks good, but I definately would use something like ip rather than name. It’s too easy for somebody to pretend to be you. I’m not so sure about the orange though, I’d look for blue or something, not quite what I expected, but nice nonetheless.

  8. avianto says:

    I am using another MT plugin for that, Compare. The same logic but using the e-mail as the password field as Dave’s suggestion. So yeah, there are 34,760+1 ways to do it.

  9. Hehe, I woke up this morning and thought “I want MY comments on MY blog to stand out.. Is that too much to ask?”
    After spending the day doing real work I stumble across this post to find you’ve just done exactly that! Now I just need to do the same in WordPress.
    Should be simple ;)

  10. Hesam says:

    I’ve done the same for my site running WordPress. It uses the same idea that Dave has suggested – relying on the email address as a password.
    I’ve used the following code:
    $theauthor = apply_filters('comment__author_email', $comment->comment_author_email);
    Then you just use an if statement to check if $theauthor is equal to your password. If it is, apply the appropriate styles. Else, apply the default comment styles.
    If you need help setting it up, let me know.

  11. Hesam says:

    Forgot to mention: That code goes into your wp-comments.php, after foreach ($comments as $comment)

  12. Hesam says:

    Oops. One last thing (I swear). Before the $theauthor statement you need to put:
    global $comment;
    Whew. Now I’m done.

  13. oVan says:

    Improving on Jeff’s comment about blue or orange: I would suggest changing the color depending on the stylesheet selected by the user.
    Jeff would choose blue stylesheet and have blue comments ;-)

  14. Benedikt says:

    The best and most secure way to do this is to provide your MT user-id with your comment. This method is much safer because no one else can pretend being you by just typing your name into the name field.
    I used to do this with my own CMS for years but eventually switched to WordPress, which is far more sophisticated but still lacking this simple feature.

  15. juque says:

    Hey Dan, long ago which I have wanted to do this in my site, very many thanks.

  16. SAPO!! says:

    on my blog (MT 2.6x based) I used the Compare PlugIn, just like avianto mentioned in an earlier comment, and I filter the comment form through the $MTCommentAuthor tag, but only because I’m so lazy ;)
    If u need more info just email me, the trick it’s working for me!

  17. Malarkey says:

    I’ve done a wee trial on my blog does a similar thing but without the plug-in. But it’s a bit ropey still, so I’ll give this a try.
    Thanks Dan

  18. Blake Scarbrough says:

    Excellent, I have been wondering how to do this. Now everybody’s blog will have this. It does make it easier to read comments and refer back to them.

  19. Simon Cox says:

    I am wondering if you can leverage something from the Typekey log-in which would guarentee that it was in fact you.
    I will have a look at this (and I encourage anyone else to as well as I may be out of my depth!)

  20. Simon Cox says:

    I have not found a way yet to get it to work with TypeKey but what if you have a class on the tag already? I am using MTRoundRobin to style my comments alternately. Fortunatly MT Switch has a default as well which manes that you can put your normal class in there:

    <dt<MTSwitch value="[MTCommentAuthor]">
    <MTSwCase value="Dan Cederholm">

    This will alternately switch between two classes (using MTRoundRobin) unless MTSwitch is triggered and we get Dans personal styling.

  21. Malarkey says:

    I’m now using a combination of MTSwitch and MTFlipFlop for comments which is a bit long-winded but seems to serve a purpose.
    I’ve added a few extra CSS selectors to give us Brit Packers a shiny new Union badge in comments too, and it’s a lot more flexible than my previous solution.
    Ta again Dan

  22. Mike Johnson says:

    Funny, I just posted a very similiar article last week to create spoof-proof highlighted comments in WordPress if anyone is interested. Its a really simple hack actually.

  23. Lauren says:

    I think the question is, Dan, who would not want to pretend to be you? ;)

  24. Josh Dura says:

    Great post Dan! Been wondering how to do this for a couple weeks now. btw – your goin down in fantasy football this week :)

  25. Thanks to Dan for starting the thread and to Hesam for saying how he does it in wordpress. It took me about 10 seconds to implement on my install!

  26. jblanch says:

    Hey, just wanted to throw a suggestion out there. I’ve made a few local band sites before, and the guestbook always gets trashed, and people always write fake names, so i implemented a simple password method by adding :password to the end of the name, (example: jblanch:mypassword) then it would just display jblanch and the speical box if right, otherwise just jblanch with no special box). It works really well.

  27. OK, I’m tired of deleting all the test comments using my name (and yes, I was asking for it). But the thread gets rather pointless…