Listing Recent Comments in MT
There are a number of ways to do this and your options are only limited by your imagination . . . and, well, the MT tags. First, this will only work in MT 2.0+ so go upgrade right now if you haven’t!
If you want to list recent comments in moveable type, you have two choices more or less:
1) You can list a specific number of recent comments in which the output will display ALL these comments regardless of whether they are all for the same entry.
2) You can list a specific number of recently commented upon ENTRIES and list the LATEST comment in that entry. The difference here is if someone makes 3 comments on one entry, only the most recent will show up.
I encourage you to PLAY with these to find what suits your needs best and look through the MT manual to explore your tags options. What I list is just an EXAMPLE of what you could do, to get you started in the right direction. I’m sure this is not the only two ways to do this, so play with the tags and have fun!
Method One:
Listing “x” number of recent comments.
<MTComments lastn=”5“>
<$MTCommentAuthorLink spam_protect=”1″$>: <$MTCommentBody remove_html=”1″ trim_to=”100″$>… [<a href="<$MTBlogArchiveURL$><$MTCommentEntryID pad="1"$>.php#<MTCommentID>">go</a>]<br/><br/>
</MTComments>
Method Two:
Listing “x” number of recently commented on entries with the last comment per entry.
May 16th, 2002 at 10:50 am
Cool! Thanks for posting this!
May 16th, 2002 at 11:39 am
Oooooh, thanks guys, I knew it had to be something relatively simple! You all rock!
May 16th, 2002 at 12:12 pm
I actually do have a quick question, though, before I try it out…..does this code have to be within the actual MT template itself, or can it be within your php include? (Probably a silly question, the answer might be obvious, but I just want to double-check?)
May 16th, 2002 at 12:17 pm
Either sets of codes should do just fine on their own. I use Method One and have it alone in a PHP include.
May 16th, 2002 at 12:38 pm
Great, thanks Lynda! I’m off to test it out now.
May 16th, 2002 at 1:19 pm
Thanks for posting this, Lynda - even the MT boards have never had a good overall thread to send people to when they ask, and now I have a good post here to direct them to
The bad thing is that I want a combination of these techniques and can’t get it to work. I like how it looks on your page, Lynda (I’m assuming you have method one), but I want it to have details about the entry, which won’t display with that method.
Ideally, I want the title of the post and the link to the post, as well as the number of comments posted. Then the name of the commenter (with a link to their page) and the first words of their comment. And all of this, I want the last 5 comments, not the last 5 posts commented on with the last comment on each.
See, I need a combo

Oh, and mine is in a module, Tricia, so it definitely can go anywhere that MT generates the data from
May 16th, 2002 at 1:26 pm
Yeah, I found it odd that they implimented two rather different ways to do this. I think they realize what people want however (to pull entry information into the comments lastn=”x” instead of the other way around) as you’re not the first person I’ve seen request that. Hopefully there will be a revision sometime soon.
I’m certain there’s a way to do this in PHP - create an entrylist and then reference a common piece of data between the two - but I’m not sure that such a bulky solution is really all that great. I mean, it would be like trying to catch a fly with three gallons on honey, you know? Or something like that.
That’s why I’m eagerly awaiting an MySQL backend on MT - if everything is in its own table, as long as it has something common between it (or you can go through another table to get something common between it) you can literally use any piece of informaiton anywhere.
May 16th, 2002 at 1:33 pm
*sigh* that’s funny…it’s just outputting the actual code itself? I am testing it on my second skin, I am putting the code right into the footer2.php include I already have, I assumed it would work this way, and all I see is the actual html coding? Really strange…I have pasted it over and over again, still coming up the same, and I also tried both methods as outlined above…..*sigh*…not that terribly important, but it’s frustrating when something won’t WORK…especially when I have gotten both Amy’s popup script and random blog scripts running just fine yesterday….
May 16th, 2002 at 1:36 pm
Ooops, I meant to say Amy’s popup script and the random blog link script from HERE heh
May 16th, 2002 at 1:36 pm
Trish - you have to create a new index template INSIDE moveable type (I’m assuming your footer2.php is not inside MT)
What I would do if I were you would be just create an index template called recent.php or something along those lines, paste the comments code into that, rebuild and then use an INCLUDE inside your footer2.php to that recent.php
Hope that helps somewhat.
May 16th, 2002 at 1:40 pm
Ahhhhhh!! See, I was beginning to think it had something to do with that…that’s why I was asking whether or not it needed to be something within MT, because they are MT tags. I guess I didn’t make myself clear. I do that sometimes
Thanks, I am gong to go try that way now lol.
May 16th, 2002 at 1:43 pm
I don’t know why I called you Trish. LOL Excuse me.
If you need to know the code for include, it’s simply this:
<? include ‘/home/username/pathto/recent.php’ ?>
May 16th, 2002 at 2:31 pm
*sigh* Someone doesn’t want me to do this LoL! I created a recent.php index file within MT (I HAVE done this before, so I know I am not crazy hah), pasted JUST the code for option #1, saved it and rebuilt, it shows up in my List Templates section, but the actual recent.php template was never created, and is nowhere on my server? What the heck? Everything has proper permissions, none of the configurations have changed recently, only thing I have done is upgrade to 2.11?? Arghhh….heh.
May 16th, 2002 at 2:33 pm
Oh…and it’s fine to call me Trish hehe…..just as long as you don’t call me Pat *shudder* (since Patricia isn’t even my name *grin*)
May 16th, 2002 at 2:39 pm
Tricia - when you created the index file, did you make sure the box labeled, “Rebuild this template automatically when rebuilding index templates” was checked?
It seems like some people’s aren’t automatically checked when they go to create a new template (although mine are).
Also make sure you put recent.php into the 2nd line under Output File:
May 16th, 2002 at 2:47 pm
Errrr…I don’t have any such box to check?? Where is that??
I did put recent.php in the second box, though. Bleh.
May 16th, 2002 at 2:51 pm
Ok, nevermind that. Forgot you hadn’t upgraded to 2.1(1) yet. You HAVE upgraded to 2.0 though, right?
And you tried Rebuilding all index files and don’t see a new file anywhere?
May 16th, 2002 at 2:53 pm
*laughs at herself* Never mind…you know, when I upgraded to MT 2.11, I forgot to upload anf replace the templates folder?? Holy cow…I need a vacation…lmao!! Let me go try this again…thanks for having so much dang patience with me *grin*
May 16th, 2002 at 2:55 pm
The second part was exactly what I was going to ask on the forum.. woohooo.. this is great! Thank you!
May 16th, 2002 at 2:57 pm
OK…well ummm…it works now *skipping through scripty goddess* Can I have another cup of coffee now? Thanks a million, Lynda…without you I never would have even figured out that I botched my upgrade hehehe.
May 16th, 2002 at 2:58 pm
Then its very possible that you aren’t all the way upgraded to 2.11 - because you should see the box. here’s a thread on the MT boards that talks about what file particularly to make sure is uploaded in the upgrade.
And dude, I see you already figured this out - you guys are too darn fast for me, but I thought I’d go ahead and post this since I found the link and everything!!!
May 16th, 2002 at 11:29 pm
Thanks for providing this info. I’d trawled the boards and manual quite a bit, but these are the easiest directions I have come across!
May 17th, 2002 at 9:12 am
I asked Eric last night how he learned PHP, and he said he was learning Perl at the same time in school, and because PHP was similar but way easier, he picked it up right away… with online tutorials and stuff. Smart boy!
But he also said that the webmonkey tutorial was good, so I looked it up, and what I read so far was really well written and easy to follow.
I think the overall webmonkey site always has good stuff, so it would be a good overall resource
June 19th, 2002 at 11:36 am
Just a quick question on this, since I do love this trick:
I noticed you have to use MTBlogURL trick to make this work. Do you know of anyway that you can simply use like MTEntryLink, or something similar? Because I have a complex archive directory, and doubt this would work for me.
June 19th, 2002 at 11:49 am
I just realized I should have said how my archives are laid out, they go like this:
archives/<Month Abbreviation><Year>/<Day>/then the entries for that day.
September 14th, 2002 at 1:28 am
yet another awesome script…! thank you for this!
quick question: the [go] link points to the anchor of the specifc comment you want to go see, but the resulting page that comes up is the individual archive for the post, and it doesn’t seem to bring you right to the comment you were looking to see…
i’m sure this is a template thing in MT and not the script, but i’m kinda braindead looking for where to fix it–any help?
November 3rd, 2002 at 2:00 am
you truely are a goddess. within minutes of coming across your site you help answer 3 of my questions and got my blog up to speed on its first day. Thank You!
November 16th, 2002 at 7:26 pm
Fantastic! Exactly what I wanted! Props to Jenn who guided me here… And I don’t think a disclaimer is necessary… As far as this guy’s concerned you ARE GODESSES!
January 2nd, 2003 at 1:32 pm
Nice script, I like it, however, the [go] link doesn’t work. See, I don’t use numerical entry IDs, my individual pages get named whatever their title is…so is there any code that tells MT that I don’t use numerical IDs…all I get is a 404 page when I click on the [go] link…
thanks,
james
January 2nd, 2003 at 2:05 pm
You could use the 2nd option of the script, and then the MTEntryLink would automatically know where your archives were by default.
January 30th, 2003 at 4:40 pm
Here’s how I did it to get the links to go to the archives properly:
<MTComments lastn=”10″ sort_order=”descend”>
<MTCommentEntry>
<$MTCommentAuthorLink spam_protect=”1″$>: <$MTCommentBody remove_html=”1″ trim_to=”100″$>… [<a title="Go read the original post: <$MTEntryTitle$>" href="<$MTEntryLink$>">go</a>]<br>
</MTCommentEntry>
<br/>
</MTComments>
February 23rd, 2003 at 10:52 am
hi there, i’ve got the script up and running, but i would like to reverse the order the comments appear - so that most recent comments appear at the top of the list. can anyone out there tell me how to do this? any tips would be appreciated.
thanks!
March 3rd, 2003 at 4:04 pm
See Beerhound’s script above -
sort_order=”descend”
June 4th, 2003 at 5:04 pm
I can get the 5 entries with the most recent comments to display in the Main Index template, but when I try to do the same thing in the category template, I get the last five entries, not that last 5 commented on.
Here’s the Main
Here’s the Category
What do you think? Thanks!
June 5th, 2003 at 12:03 pm
I’ve taken out the recently commented on entries in my category archive until I can get it to work properly. So that second link above will not show what I’m talking about.
September 18th, 2003 at 2:08 am
I am trying to use method (2), but I get the following message when I rebuild:
MT::App::CMS=HASH(0×8391a10) Use of uninitialized value in concatenation (.) or string at lib/MT/ObjectDriver/DBI.pm line 75.
I copy and pasted the code onto my index template.
Can anyone help?
Koki
September 23rd, 2003 at 2:37 pm
thank you for your script it worked great on our site!
December 9th, 2003 at 6:10 am
¿How can I filter my comments (the author of the blog) from that list?
Thank you!
February 18th, 2004 at 8:18 am
Thank-you, this worked beautifully.
July 17th, 2004 at 6:56 pm
Thanks so much for the script. Method 2 worked first time with dated archives.