Chapter 7: Comments
Displaying Comments
Problem
You want to display comments in your weblog.
Solution
Use the template tags prefixed with MTComment.
Discussion
The default templates that ship with Movable Type are comment-ready. These templates are set up so that comments appear on both the popup comment window and the individual archive pages.
All of the various options for moderating and managing comments combine to make the default template code and HTML for comments quite extensive and sophisticated. To get you familiar with how comments can be implemented in MT templates we'll look at some basic examples. Once you become more familiar with how the comment tags work and can be combined, you can look at the default templates and modify them to suit your preferences and purposes.
Let's look at a simple comment display that may be inserted following the contents of a post on an individual entry archive template.
<MTIfCommentsActive>
<h2 id="comments">Comments</h2>
<MTComments>
<div id="c<$MTCommentID$>">
<$MTCommentBody$>
</div>
<p>Posted by: <$MTCommentAuthorLink spam_protect="1"$>
<$MTCommentAuthorIdentity$> at
<$MTCommentDate$></p>
</MTComments>
</MTIfCommentsActive>
The first line, MTIfCommentsActive, is a conditional
tag that will render the contained HTML and template tags if comments
exists or are being accepted for the entry. Next we add a section heading
with an anchor of "Comments" that will allow links to this section.
Used in this context, MTComments will select and loop
through all comments for the associated entry, using the values set in the
weblog's preferences. These preferences (sort order etc) can be selectively
overridden with attributes added to the MTComments tag. (See
the entry for Comments in Appendix A for more on these
attributes.)
The comment ID (MTCommentID) is placed in a HTML
div tag so that individual comments can be linked, while the
div tag wraps the comment body
(MTCommentBody).
The comment ends with a posted-by footer that uses
MTCommentAuthorIdentity, MTCommentDate, and
MTCommentAuthorLink.
Should we explain where the commenter name comes from relative to TypeKey usage.
MTCommentAuthorIdentity. A link to the commenter's TypeKey profile with the link text of the TypeKey username.
MTCommentDate is the timestamp designating when the comment
was submitted. The format used is dependent upon the weblog's preferences
or can be modified using the format argument and the standard
Date Tag Formats. See Appendix A
for more.
MTCommentAuthorLink inserts the commenter's name with a
hyperlink if possible. Depending upon the information given by the
commenter, this tag will return different results. See MTCommentAuthorLink for more information on using this tag.
For those who are (potentially) displaying email addresses, adding the
spam_protect global filter with a value of 1 (true) is a good
idea. More on this in "Protecting Email Addresses from Spammers".
Does MTCommentURL use the redirect mechanism?
The block then closes the MTComments and
MTEntryIfCommentsActive tag contexts.
Conditional Tags
Getting a bit more sophisticated, there are a couple of comment-related conditional tags you'll want to be aware of.
MTEntryIfCommentsAccepted is a conditional tag that will
render its contents if comments on the entry are closed as opposed to the
MTEntryIfCommentsActive which will render its contents if
comments exists.
MTIfRegistrationRequired is a conditional tag that will
only render its results if a reader has signed into the system's designated
authentication system.
Like all conditional tags each of these can be used with the
MTElse tag to render only if the opposite is true. (See "Publishing Content When a Conditional is False" for more.)



