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:
<MTSwitch value="[MTCommentEmail]"><MTSwCase value="name@example.com"> class="r"</MTSwCase></MTSwitch>
What came out in the other end was this:
class="r"</MTSwCase></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:
<MTIfEqual a="[MTCommentEmail]" b="name@example.com">class="r"</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:
<?phpif ("<$MTCommentEmail$>" == "name@example.com") {?> class="r"<?php} ?>
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 ;)
- Previous post: Stylegala v.02
- Next post: Various Artists: Verve Remixed 2
Information, sponsorship, and externals
About the author
Roger Johansson is a Swedish web professional specialising in web standards, accessibility, and usability. More about me and this site.
Latest articles
- Validation statistics from Nikita the Spider Comments off
- An analysis of the sites crawled by the bulk validation tool Nikita the Spider during March 2008.
- Authentic Jobs API and Affiliates program Comments off
- The Authentic Jobs job listing service now has a public API and an affiliate program.
- What does Acid3 mean to you and me? Comments off
- Opera and Apple have announced that their web browsers pass the Acid3 Browser Test, but how will that help web designers and developers?
- Designing Web Navigation (Book review) Comments off
- Learn the fundamentals of navigation design and design better navigation systems for large and small sites as well as for web based applications.
- DOMAssistant bundle for TextMate Comments off
- To save keystrokes and speed up development I have created a DOMAssistant bundle for TextMate.
- First impressions of Internet Explorer 8 Beta 1 Comments off
- My impressions after trying out Internet Explorer 8 Beta 1 for a couple of days.









Comments
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="gabriel5@individualism.ro">class="myComment"</MTSwCase> <MTSwDefault>class="comment"</MTSwDefault> </MTSwitch>
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.
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.
I used the php version in your post and it works great and is easy to implement. Great article.
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 (?)
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 >.
Using the email field also ensures uniqueness: whilst no two people can share email addresses, shared names are common.
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.
Pete: Thanks :)
I recently set out to do the same on my own blog (writeup: http://pollas.dk/blog/archives/2004/09/29/blogredesignepisode_7)
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.
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$>" == "name@example.com")), then it always gives me false.
I've tried spam_protect="0", but it still isn't functioning right. Any ideas?
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.
Sorry, comments are closed for this post.