Learning Movable Type: Recent Comments


mtbadge-small.gifUpdated.

Adding a Recent Comments section to your weblog is easy and straightforward. There are two basic approaches. The first is to list the last N number of recent comments; the second the last N most recently commented on entries.


The Most Recent Comments

recent_comments1.gif In this example of Recent Comments the last 10 comments are listed, regardless of how many times there may have been comments to the same entry. The comment authors names are linked to their respective websites, if they have them, and the entry title is linked to the author's comment in the entry.

For most recent comments like shown in the example to the left, add the following code to the sidebar section of the Main Index Template. There are various customizations you can make to the code. If you want a different number of comments, change the lastn attribute to another number. Setting the "show_email" attribute of the MTCommentAuthorLink tag to zero guarantees that your commenters' email addresses will not be displayed. Alternatively you could set the attribute spam_protect to 1 which would modify the displayed email address to make it more difficult for spam bots to harvest. More modifications are described in the MT manual.

Using MT3.2 default templates and styles:

<div class="module">
<h2 class="module-header">Recently Commented On</h2>
<div class="module-content">
<ul class="module-list">
<MTComments lastn="10" sort_order="descend">
<li class="module-list-item">
<$MTCommentAuthorLink show_email="0"$> on <MTCommentEntry>
<a href="<MTEntryPermalink>#c<$MTCommentID$>"><$MTEntryTitle$></a>
</MTCommentEntry>
</MTComments>
</li>
</ul>
</div>
</div>

Using MT3.15 default templates and styles:

<h2>Recent Comments</h2>

<ul><li>
<MTComments lastn="10" sort_order="descend">
<p><$MTCommentAuthorLink show_email="0"$> on <MTCommentEntry>
<a href="<MTEntryPermalink>#c<$MTCommentID$>"><$MTEntryTitle$></a>
</MTCommentEntry>
</MTComments>
</li></ul>

Using MT2.661 default templates and styles:

<div class="sidetitle">Recently Commented On</div>

<div class="side">
<MTComments lastn="10" sort_order="descend">
<p><$MTCommentAuthorLink show_email="0"$> on <MTCommentEntry>
<a href="<MTEntryPermalink>#c<$MTCommentID$>"><$MTEntryTitle$></a>
</MTCommentEntry>
</MTComments>
</div>


Another way to show Recent Entries is to have the author name link to the author's comments and the entry title link to the entry. The code for this method is the following:

<MTComments lastn="10" sort_order="descend">
<p><MTCommentEntry>
<a href="<MTEntryPermalink>#c<$MTCommentID$>"><$MTCommentAuthor$></a> on
<a href="<MTEntryPermalink>"><$MTEntryTitle$></a>
</MTCommentEntry>
</MTComments>




The Entries Most Recently Commented On

Recently Commented On
recent_comments.gif

In this example of Recently Commented On the last 6 entries that have been commented on are listed.

For entries most recently commented on, add the following code to the sidebar section of the Main Index Template. You can tweek elements of the code to customize it more for your needs. For example, if you want to show more or less than 5 most recently commented on entries, change the 5 listed after recently_commented_on=" to another number.

Using MT3.2 default templates and styles:

<div class="module">
<h2 class="module-header">Recently Commented On</h2>
<div class="module-content">
<ul class="module-list">
<MTEntries recently_commented_on="5" sort_order="descend">
<li class="module-list-item">
<a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a> (<$MTEntryCommentCount$>)<br />
<MTComments lastn="1"><$MTCommentAuthorLink show_email="0"$> wrote:
<$MTCommentBody trim_to="35" remove_html="1" convert_breaks="0"$>...
[<a href="<$MTEntryLink$>#c<$MTCommentID$>">more</a>]<br />
</MTComments>
</MTEntries>
</li>
</ul>
</div>
</div>

Using MT3.15 default templates and styles:

<h2>
Recently Commented On
</h2>

<ul><li>
<MTEntries recently_commented_on="5" sort_order="descend">
<a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a> (<$MTEntryCommentCount$>)<br />
<MTComments lastn="1"><$MTCommentAuthorLink spam_protect="1"$> wrote:
<$MTCommentBody trim_to="35" remove_html="1" convert_breaks="0"$>...
[<a href="<$MTEntryLink$>#c<$MTCommentID$>">more</a>]<br /><br />
</MTComments>
</MTEntries>
</li></ul>

Using MT2.661 default templates and styles:

<div class="sidetitle">
Recently Commented On
</div>

<div class="side">
<MTEntries recently_commented_on="5" sort_order="descend">
<a href="<$MTEntryPermalink$>"><$MTEntryTitle$></a> (<$MTEntryCommentCount$>)<br><MTComments lastn="1">
<$MTCommentAuthorLink spam_protect="1"$> wrote:
<$MTCommentBody trim_to="35" remove_html="1" convert_breaks="0"$>...[<a href="<$MTEntryLink$>#c<$MTCommentID$>">more</a>]<br /><br /></MTComments>
</MTEntries>
</div>

Save and rebuild your Index Template.

Note:
The above code assumes that your Preferred Archive Type is set to Individual. If it isn't (check your preferences in your weblog config) add the archive_type attribute to the MTEntryPermalink tag like so:

<MTEntryPermalink archive_type="Individual">

Links:
Girlie's tips on Comment Listing
MT Forum Thread on Recent Comments
MT Wiki on Recent Comments
Recently Commented On Entries in Category Archives - TweezerMan's fix to the problem that recently commented on entries doesn't work in category archives.
Movalog on different ways to do Recent Comments
Recently Commented On Entries in Category Archives - Tweezerman's solution to narrowing recently commented on entries to specific categories.


Posted by Elise Bauer on February 3, 2006 1:27 PM to Learning Movable Type http://www.learningmovabletype.com/