February 03, 2006

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.


Has this tutorial been helpful? Please consider linking to Learning Movable Type at http://learningmovabletype.com/ . Thanks!

Posted by Elise Bauer on February 03, 2006 to Comments and Trackbacks
Comments(7) | Email to a friend | Printer-friendly version


Trackback

If you would like to send a trackback
please use the following URL: http://learningmovabletype.com/cgi-bin/mt32/mt-tb.cgi/186

» Template changes from Carpe Bonum
I've made a couple of changes to Carpe Bonum's Movable Type template files. First, I have added sidebars to all the Archive page templates. Readers arriving via permalinks to individual post archive pages will now see the same sidebar as......[read more]

Tracked: April 6, 2005 02:26 AM

Comments

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?

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

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?

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.

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://learningmovabletype.com/archives/001532how_to_style_author_comments_differently_on_your_mt_blog.php


Post a comment

(Before posting a comment please see the Comments and Trackbacks Policy. Do you need help troubleshooting your weblog? Please post questions and requests for support at the MT Support Forums. Thanks!)




Remember Me?

(you may use HTML tags for style)

Email to a friend

Email this article to:


Your email address:


Message (optional):