Differentiating Author Comments in Movable Type 4
October 23, 2007 | | Comments (0)

We’ve discussed how to implement alternating comment styles. Another useful option for customizing comment displays is to apply a different style to comments left by an entry’s author. This allows readers to quickly and easily find the author’s contributions in the comments. I find this particularly useful in conversations that have several commenters or conversations where the author is a frequent responder.

Movable Type 4 has a new tag that makes applying a different style to author comments dead simple. This tag is so simple and straight forward even the Movable Type documentation is clear on it (I tease because I love you MT documentation).

<mt:IfCommenterIsEntryAuthor>
  <!-- do something -->
</mt:IfCommenterIsEntryAuthor>


The “do something” in our case is to apply a different style in the cases where a comment’s author is the same as an entry’s author.

The first step toward applying a different style is of course creating that style. A simple example of an author style:
.author {
font-weight:bold;
border:2px solid black;
}

After you’ve placed that code in your stylesheet it’s time to dig into the Comment Detail template module. Before I show you this sample code let me say that there are other ways to do this. Probably shorter, more efficient blocks of code. However, this one works well for me, and the way my brain works, so it’s the one I use.

<mt:IfCommenterIsEntryAuthor><div class="author">
<mt:if name="__odd__">
<div class="odd">
<mt:else>
<div class="even">
</mt:if>

<div class="comment"<MTIfArchiveTypeEnabled archive_type="Individual"> id="comment-<$MTCommentID$>"</MTIfArchiveTypeEnabled>>
    <div class="inner">
        <div class="comment-header">
            <$MTCommentAuthorLink default_name="Anonymous" show_email="0"$> <MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty>
said:
        </div>
        <div class="comment-content">
            <$MTCommentBody$>
        </div>
        <div class="comment-footer">
            <a href="#comment-<$MTCommentID$>" title="Permalink to this comment"><$MTCommentDate format="%x %X"$></a>
</div><!--End Author Class-->

<mt:else> <mt:if name="__odd__">
<div class="odd">
<mt:else>
<div class="even">
</mt:if>

<div class="comment"<MTIfArchiveTypeEnabled archive_type="Individual"> id="comment-<$MTCommentID$>"</MTIfArchiveTypeEnabled>>

    <div class="inner">
        <div class="comment-header">
            <$MTCommentAuthorLink default_name="Anonymous" show_email="0"$> <MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty>

said:
        </div>
        <div class="comment-content">
            <$MTCommentBody$>
        </div>
        <div class="comment-footer">
            <a href="#comment-<$MTCommentID$>" title="Permalink to this comment"><$MTCommentDate format="%x %X"$></a>

</mt:IfCommenterIsEntryAuthor>
        </div>
    </div>
</div>
</div><!--End odd or even class-->

You’ll notice that this contains the code for alternating comments as well as as the IfCommenterIsEntryAuthor stuff. So implementing this as is (with accompanying styles in your stylesheet of course) will give you 3 different styles in your comments. One for even comments, one for odd comments and one for author comments. You’ll want to double check any inheritance issues in your CSS so that your author style doesn’t get dominated by either the even or odd class (because remember your author comments are going to be either even or odd in addition to being an author comment).

As always if I've made any mistakes or if you have any questions please let me know. Thank you for reading.


Share this post:
digg del.icio.us reddit Newsvine Google Bookmark FaceBook Stumble Upon

Leave a comment