Movable Type Docs > Movable Type 4.15

Comment Threading

Comment threading is the ability for readers to respond to specific comments on a blog, web site or forum, and for other readers to more easily follow that conversation by seeing which comments are in response to others.

There are generally two types of threading one can deploy on their blog:

Chronological Threading

This is where comments are displayed strictly in chronological order with a simple note saying, "this comment is in response to So-and-so's comment".

chron_threads.png

Hierarchical Threading

This is where comments appear nested, meaning comments in response to other comments appear next to one another.

digg_hier_thread.png

Installing Threaded Comments

Starting with Movable Type 4.15, Movable Type's default templates will have chronological threading support built in. Any new blog, web site or forum created using Movable Type will not need to modify their templates in order to take advantage of this feature.

Users upgrading to Movable Type 4.15 however will need to make slight modifications to their templates in order to create threaded comments on their site.

Setting up the Reply To links

  1. The first step is to add the <MTCommentReplyLink> template tag where you would like the Reply link to appear. This must be within an <MTComments> container tag. We recommend placing it in the comment posted byline:

    <p class="comment-footer">
      Posted by
      <$MTCommentAuthorLink default_name="<MT_TRANS phrase="Anonymous">"$> <$MTCommentAuthorIdentity$> |
      <a href="#comment-<$MTCommentID$>"><$MTCommentDate$></a> |
      <MTCommentReplyLink>
    </p>
    

    By default, MTCommentReplyLink creates a link with the text Reply. However, this can be customized by giving the tag an optional text attribute like so, for example <MTCommentReplyLink text="Reply to this comment">.

  2. The next step is to use a new <MTRepliedComment> container tag to show who the commenter is replying to. You can use any of the MTComment template tags you find in Movable Type within an MTRepliedComment container as well as <MTElse> which can be used as the "default" (i.e. if the comment is a new thread and not replying to someone else). Once again, this tag must be placed within an <MTComments> container tag and we recommend the posted byline:

    <p class="comment-footer">
      <MTRepliedComment>Posted, in reply to <a href="#c<MTCommentID>"><MTCommentAuthor>'s comment</a>, 
      by<MTElse>Posted by</MTElse></MTRepliedComment>
      <$MTCommentAuthorLink default_name="<MT_TRANS phrase="Anonymous">"$> <$MTCommentAuthorIdentity$> |
      <a href="#comment-<$MTCommentID$>"><$MTCommentDate$></a> |
      <MTCommentReplyLink>
    </p>
    

    So with the above example, if the comment was replying to someone else, the posted byline would read:

    Posted, in reply to X's comment, by Y
    

    Whereas if it were a new thread, it would simply read:

    Posted by Y
    
  3. The final step is to add the MTCommentReplyField template tag within your comment form. We recommend it is added straight after the "remember me" checkbox:

    <p>
      <label for="comment-bake-cookie"><input type="checkbox"
         id="comment-bake-cookie" name="bakecookie" onclick="if (!this.checked) forgetMe(document.comments_form)" value="1" />
         Remember personal info?</label>
    </p>
    <MTCommentReplyField>
    

Once these changes are made, make sure to rebuild the necessary files!

Chronological Comment Threading

Chronological Threads display comments sorted by the date they were posted. If a comment was posted in reply to another, this information is shown inline rather than indenting the entire comment (thus creating a hierarchy).

The following steps guide you through editing your templates to display chronological threads. These instructions have been tailored to match the default templates. If you have customized your comment templates, these are bound to be different so you will have to adapt the logic:

  1. Open the Comment Detail template module and search for:

    <$MTCommentAuthorLink default_name="Anonymous" show_email="0"$> 
    <MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty> said:
    
  2. To change this to a chronological thread, we will need to first check if the comment is a reply (i.e. if it has a parent). If it does, replace said with something more appropriate. Something like this works great:

    <!-- This displays the commenter's name and is the same as before -->
    <$MTCommentAuthorLink default_name="Anonymous" show_email="0"$> 
    <MTIfNonEmpty tag="CommentAuthorIdentity"><$MTCommentAuthorIdentity$></MTIfNonEmpty> 
    <!-- Check if the comment has a parent i.e. is it a reply? -->
    <MTIfCommentParent>
        <MTCommentParent> <!-- Set the context to the parent -->
            <a href="#comment-<MTCommentID>">replied to <MTCommentName>'s comment</a>
        </MTCommentParent>
    <MTElse> <!-- If this isn't a reply then -->
        said
    </MTIfCommentParent>
    
  3. Republish your templates. Your comments should now be in a chronological thread, for example:

mt_chron_thread.png

Hierarchical Comment Threading

Hierarchical Threads are the more traditional way of displaying comment threads. Here, "top level" comments (i.e. those without replies) are sorted by date. For each comment, replies to it are listed underneath and indented slightly.

The following steps guide you through editing your templates to display hierarchical threads. These instructions have been tailored to match the default templates. If you have customized your comment templates, these are bound to be different so you will have to adapt the logic:

  1. Open the Comments template module and search for this line:

    <$MTInclude module="Comment Detail"$>
    
  2. To change this into a hierarchical thread, we will need to look through the top level comments and for each top level comment, look through its replies (indenting each one as appropriate). Something like this works great:

    <MTIfCommentParent><MTElse> <!-- This conditional checks to make sure that this comment isn't a reply -->
       <!-- Display the top level comment -->
       <$MTInclude module="Comment Detail"$>
       <MTCommentReplies> <!-- Here we loop through the replies and for each reply -->
       <!-- if it is the first of that "level/depth", indent it -->
       <MTCommentsHeader><div style="margin-left: 20px;"></MTCommentsHeader>
       <!-- Display the comment -->
       <MTInclude module="Comment Detail">
       <!-- And loop through this container for replies of replies and so on -->    
       <MTCommentRepliesRecurse>
       <!-- If this reply is the last of that "level/depth" close the div we opened to indent -->   
       <MTCommentsFooter></div></MTCommentsFooter>
       </MTCommentReplies>
    </MTIfCommentParent>
    
  3. Republish your templates. Your comments should now be in a hierarchical thread, for example:

mt_hier_thread.png

About this feature

This feature was the result of the gracious contribution of Simply Threaded by Arvind Satyanarayan. Thank you Arvind!

This page was last updated on 2008-05-08, 09:49.  

Submit a User Contributed Note

User contributed notes are a great way to share the knowledge you have gained in using Movable Type.

If you have a technical question or problem, please visit Movable Type Support.

(If you haven't left a note here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)