Description

MTThreadedComments adds full-fledged threaded commenting features to a Movable Type weblog. Inspired by the comment features of LiveJournal, it adds threading and subject lines to Movable Type comments. This means your readers can carry on more complex discussions, adding their own titles and replying directly to other comments.

Note: MTThreadedComments includes a standard Movable Type plugin to add new tags, but it also requires modification of the main Movable Type source code. Do not install MTThreadedComments unless you are comfortable modifying your Movable Type installation.

Download

Current version: 0.1.1
Plugin | Patch

Installing MTThreadedComments

Requirements

Installation

  1. Copy MTThreadedComments.pl into your Movable Type plugins directory.
  2. Apply the patch to the Movable Type library. If you are using a standard Unix-like shell, cd to your Movable Type directory (the one that contains mt.cgi, lib, extlib, etc…) and type the following command:
    patch -p0 < /path/to/where/you/downloaded/mt-threaded-comments.patch
    Watch the output of the patch command for any errors.
  3. If you are using a database to store your weblog (i.e., not DBM files), you will need to modify your database scheme. You will need to add comment_subject and comment_parent_id columns to the mt_comment table. You might use SQL commands similar to the following:
    alter table mt_comment add column comment_subject text
    alter table mt_comment add column comment_parent_id integer
    alter table mt_comment add index comment_parent_id
    

Documentation

Configuring your weblog

After installing MTThreadedComments, you will need to make some major changes to your weblog templates to accomodate the new comment features. Below I give examples based on my weblog and the default Movable Type templates. If you have customized your weblog templates significantly, make these changes carefully.

Designing your comment workflow

In the default Movable Type setup, both the Comment Listing Template and the Individual Entry Archive template display all the comments on an entry, and provide a form for adding a new comment. We will change this. The following steps will configure your weblog as follows:
  • The Individual Entry Archive will be the only listing of your comments, and will not contain a form to post new ones. This would be too confusing, as you can now not only post a comment about an entry, but reply to an existing comment. So the comment posting form needs to be dynamic.
  • The Comment Listing Template (shown by the mt-comments.cgi script) will contain the sole form for posting comments. It will no longer show all comments on an entry, but instead will show only the entry or comment that is being responded to.
  • We will use inline comments. If you prefer to use popup windows for your comments (I don’t), you will need to add the appropriate JavaScript yourself.

Altering the Individual Entry Archive template

Make the following changes to the Individual Entry Archive template:
  1. Remove the comment posting form (from <form to </form>). Replace it instead with a link to the comment posting CGI script:
    <a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>">"Post 
    a new comment</a>
    
  2. Replace the comment listing—that is, the part enclosed by <MTComments>—with this:
    <MTRootComments>
    <div class="comments-body">
    <$MTInclude module="Nested Comments" $>
    </div>
    </MTRootComments>
    
    Note that if you are using anything other than <MTComments> (for example, if you have any attributes), you will not be able to use <MTRootComments>. Instead, continue using your current container tag to list your comments, but use <MTCommentUnlessParent> to restrict output to only the root comments in the entry. If you use SimpleComments, your comment listing might look like this:
    <MTSimpleComments>
    
    <MTSimpleCommentIfComment>
    <MTCommentUnlessParent>
    <div class="comments-body">
    <$MTInclude module="Nested Comments">
    </div>
    </MTCommentUnlessParent>
    </MTSimpleCommentIfComment>
    
    <MTSimpleCommentIfTrackback>
    <!-- your trackback code here -->
    </MTSimpleCommentIfTrackback>
    </MTSimpleComments>
    

Creating the Nested Comments template

Use your weblog menu to create a new template module, named “Nested Comments”. The contents should be as follows:

<MTIfCommentSubject>
<h3 class="title"><$MTCommentSubject$></h3>
</MTIfCommentSubject>
<$MTCommentBody$>
<span class="comments-post"><b>Posted by:</b>
<$MTCommentAuthorLink spam_protect="1"$> on <$MTCommentDate$>
<MTEntryIfCommentsOpen>
| <a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>;parent_id=<$MTCommentID$>">Reply to this</a>
</MTEntryIfCommentsOpen>
</span>

<MTCommentIfChildren>
<div class="comments-nest-box">
<MTCommentChildren>
<div class="comments-body">
<$MTInclude module="Nested Comments" $>
</div>
</MTCommentChildren>
</div>
</MTCommentIfChildren>
This template (included by the Individual Entry Archive for each root comment) formats and displays a comment, and then recursively includes itself for each child comment. This is what allows nested comments to display correctly.

Altering the Comment Listing Template

Make the following changes to the Comment Listing Template:
  1. Replace the comment listing (from <MTComments> to </MTComments>) with this:
    <MTCommentPreviewUnlessParent>
    <div class="blogbody">
    <h3 class="title"><$MTEntryTitle$></h3>
    <$MTEntryBody$>
    <$MTEntryMore$>
    <div class="posted"><p>Posted by <$MTEntryAuthor$>
    at <$MTEntryDate$></p></div>
    </div>
    </MTCommentPreviewUnlessParent>
    
    <MTCommentPreviewIfParent>
    <MTCommentPreviewParent>
    <div class="comments-body">
    <h3 class="title"><$MTCommentSubject$></h3>
    <$MTCommentBody$>
    <span class="comments-post">Posted by
    <$MTCommentAuthorLink spam_protect="1"$> at <$MTCommentDate$></span>
    </div>
    </MTCommentPreviewParent>
    </MTCommentPreviewIfParent>
    

    This will display the context being replied to. You may wish to change the contents of the <div class="comments-head"> tag above the context to reflect its new nature.

  2. Add the following to the post form, above the Comments: text area label:
    <input type="hidden" name="static" value="1" />
    <input type="hidden" name="parent_id" value="<$MTCommentPreviewParentID$>" />
    
    <label for="subject">Subject:</label>
    
    <MTCommentPreviewUnlessParent>
    <input id="subject" name="subject"
           value="Re: <$MTEntryTitle encode_html="1" $>" />
    </MTCommentPreviewUnlessParent>
    
    <MTCommentPreviewIfParent>
    <MTCommentPreviewParent>
    <input id="subject" name="subject"
           value="<$MTCommentResponseSubject encode_html="1" $>" />
    </MTCommentPreviewParent>
    </MTCommentPreviewIfParent>
    
    <br /><br />
    
    This adds a Subject entry box to the form, and populate it with the appropriate values. The parent_id value is used for threading (to indicate where to nest the new comment), and setting the static value tells Movable Type to redirect back to the entry archive page after posting the comment, since the Comment Listing Template is no longer appropriate for this.

Altering the Comment Preview Template and Comment Error Template

Make the following changes to both the Comment Preview Template and the Comment Error Template:
  1. Add the following to the comment editing form, above the Comments: text area label:
    <input type="hidden" name="parent_id" value="<$MTCommentPreviewParentID$>" />
    
    <label for="subject">Subject:</label>
    <input id="subject" name="subject"
           value="<$MTCommentPreviewSubject encode_html="1"$>" /><br /><br />
    

Altering the Stylesheet template

In order for threaded comments to appear nested in your comment listing, you will need to add a nested command style to tell your browser how to display nested comments. To display nested comments as they appear in my weblog, add this to your Stylesheet template:

	.comments-nest-box {
		padding-left:15px;
		border-left:5px solid #AAA;
	}

Altering the index templates

Finally, you will need to alter any templates that link to your comment script or individual entry archive. This includes the Main Index, Date-Based Archive and Category Archive templates.

Find the section in each template that links to the comments. It will probably be wrapped in a <MTEntryIfAllowsComments> tag. In the default templates, it is located between the date posted and the trackback link. We want to replace the comment link with the following:

<MTEntryIfAllowComments>
| <a href="<$MTEntryLink type="Individual"$>#comments">Comments
  (<$MTEntryCommentCount$>)</a>
<MTEntryIfCommentsOpen>
| <a href="<$MTCGIPath$><$MTCommentScript$>?entry_id=<$MTEntryID$>">Post
  a new comment</a>
</MTEntryIfCommentsOpen>
</MTEntryIfAllowComments>

This provides a link to the comment section of the individual entry archive to read existing comments, and a link to the comments CGI script to post a new one.

Comment Subject Tags

The following tags are available for use in displaying information about the subject of a comment. Except where noted, they require that a comment be in context, e.g., within a <MTComments> tag:

  • MTCommentSubject
    The subject of this comment. Blank if this comment has no subject.
  • MTIfCommentSubject
    A container tag; the markup between <MTIfCommentSubject> and </MTIfCommentSubject> will be displayed if this comment has a subject.
  • MTUnlessCommentSubject
    A container tag; the markup between <MTUnlessCommentSubject> and </MTUnlessCommentSubject> will be displayed if this comment does not have a subject, or if the subject is the empty string.
  • MTCommentResponseSubject
    An appropriate subject for responding to this comment. This is normally “Re: ” followed by the subject of the current comment, unless the comment has no subject or the subject already starts with Re.
  • MTCommentPreviewSubject
    The subject of the comment you are previewing. This tag can be used only when a comment is being previewed, e.g., in the Comment Preview Template or the Comment Error Template.

Comment Threading Tags

The following tags are available for use in displaying information about comment threading. Except where noted, they require that a comment (or comment preview, for tags with Preview in the name) be in context, e.g., within a <MTComments> tag.

Comments are threaded in a tree structure; the children of a comment are those comments that are direct replies to it (replies to replies are not children, but children of children). Root comments are those that are attached directly to an entry, and are not replies to another comment.

  • MTRootComments
    A container tag representing a list of root comments; the markup between <MTRootComments> and </MTRootComments> will be displayed once for each root comment in the entry. The comments will be displayed in the order they were posted. This tag can be used in an entry context.
  • MTCommentChildren, A container tag representing the list of children of this comment; the markup between <MTCommentChildren> and </MTCommentChildren> will be displayed once for each comment that is a direct child of the current comment, in the order they were posted.
  • MTCommentIfChildren
    A container tag; the contents of this container will be displayed if the current comment has at least one child.
  • MTCommentParent, MTCommentPreviewParent
    A container tag representing the parent of the current comment (or comment preview). This allows you to use <$MTComment*$> tags to refer to the parent comment. After you end this context, tags return to referring to the current comment.
  • MTCommentParentID, MTCommentPreviewParentID
    The numeric ID of the parent of this comment (or comment preview). Displays 0 if the current comment is a root comment (has no parent).
  • MTCommentIfParent, MTCommentPreviewIfParent
    A container tag; the contents of this container will be displayed if the current comment (or comment preview) has a parent, i.e., if it is not a root comment.
  • MTCommentUnlessParent, MTCommentPreviewUnlessParent
    A container tag; the contents of this container will be displayed if the current comment (or comment preview) does not have a parent, i.e., if it is a root comment.

Caveats

  • If you are displaying comments using templates like those above, and you delete a comment that has replies, those replies will no longer appear in the comment listing.
  • Subjects and threading information is not exported by the Movable Type export functionality. If you are using this to back up your weblog, be aware that comment subjects and threading will not be backed up.

Version History

0.1.1

  • Fix typo that caused MTCommentParent to return a template error.

0.1

  • Initial release

Known Bugs

None

Contact the Author

Please send any comments or suggestions to Alexei Kosut at akosut@cs.stanford.edu or comment below.

Related weblog entries

Comments & Trackbacks