« Adding a "Posted to Category" Line | Main | How to Style 'Author' Comments Differently on Your MT Blog »

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.

Comments (12)

NewMexiKen Author Profile Page:

With MT 3.16 I tried the first of your suggested coding above and got a MYSql error. It's requiring that I have MTEntries instead of beginning as you do with MTComments. But I no longer want the recent comments listed by entry; I want just what you have.

Any ideas what my bug could be?

NewMexiKen Author Profile Page:

Addendum: The Recent Comments code (first sample above) seems to work on a static page, but not on the dynamic pages I use. ???

Aruna Author Profile Page:

I just tried using the last Recently Commented on template at the bottom of this page, and it doesn't work either. Maybe something changed from 3.121 to 3.17? The only difference now is that I'm using mySQL instead of Berkeley DB?

dannyFoo Author Profile Page:

Hey elise, I'm not sure what's wrong but I just noticed, if the comment author wasn't an authorized TypeKey, their names wouldn't come out in the list. Hmm.. know what's the problem?

Cheers.

kiffin Author Profile Page:

So what if I want to filter out my own comments from the list, is that possible?

Hi all,
The best place to ask questions like these is at the MT Support Forums.

Kiffin - It used to be possible to filter out your own comments. I remember seeing something posted at the support forums a couple years ago to that effect. That is where I would look first.

Kiffin, you can do it using the Compare plugin, I just grabbed that idea from here:

http://www.learningmovabletype.com/archives/001532how_to_style_author_comments_differently_on_your_mt_blog.php

Is it possible to filter the comment from the list ?

Will Recently Commented On as you display the code work in 4.01?


I have no idea. The most recent update for this code was for MT 3.2. ~Elise

There is a recently_commented_on in the MT 4.01 code, so it ought to work. As with many things, the best way to find out is just to try.

Shawn:

We need to show comments from all categories. We're using MT4 and have the comments in their own module template. Here's what we have right now:

<mtentries recently_commented_on="4">
<MTComments lastn="1">
<div class="Recent"><a href="<mt:EntryPermalink />"><$MTCommentDate format="%m/%d/%y"$> - <u><$MTCommentAuthor$></u> commented on '<$MTEntryTitle$>'</a></div>
</MTComments>
</mtentries>

this, of course, only shows one from each of our mutliple categories. I tried to remove the mtentries tag, but that gets flagged by the index file for not having the mtentries tag. Any thoughts on how to show the four most recent comments, regardless of whether they're from the same post?

@Shawn -

The problem is that you are using tags that reference the entry directly, without setting up the entry context. Because of that, you are getting the errors.

To avoid it, do something like this instead:

<MTComments lastn="4">
  <MTCommentEntry>
    <div class="recent">
      <a href="<$MTEntryPermalink$>"><$MTCommentDate format="%m/%d/%y"$> - <u><$MTCommentAuthor$></u> commented on '<$MTEntryTitle$>'</a>
    </div>
  </MTCommentEntry>
</MTComments>

What you are doing is grabbing the last four entries, then creating an entry context for each with the MTCommentEntry container. Inside of that you can then use your entry tags as normal. You can use this inside your index template. Just change the lastn attribute (currently 4) to whatever you would like.

Post a comment

(If you haven't left a comment here before, your comment may need to be approved before will appear on the entry. Thanks for waiting.)