scriptygoddess

16 May, 2002

Listing Recent Comments in MT

Posted by: Lynda In: MT hacks

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.

<MTEntries recently_commented_on="5">

<a href="<$MTEntryLink$>"><$MTEntryTitle$></a><br/>
<MTComments lastn="1"><$MTCommentBody remove_html="1" trim_to="100"$>… <br/>
by <$MTCommentAuthorLink spam_protect="1"$></MTComments>

<br/><br/>
</MTEntries>

40 Responses to "Listing Recent Comments in MT"

1 | Jennifer

May 16th, 2002 at 10:50 am

Avatar

Cool! Thanks for posting this! :)

2 | Tricia

May 16th, 2002 at 11:39 am

Avatar

Oooooh, thanks guys, I knew it had to be something relatively simple! You all rock! 😀

3 | Tricia

May 16th, 2002 at 12:12 pm

Avatar

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?)

4 | Lynda

May 16th, 2002 at 12:17 pm

Avatar

Either sets of codes should do just fine on their own. I use Method One and have it alone in a PHP include. :)

5 | Tricia

May 16th, 2002 at 12:38 pm

Avatar

Great, thanks Lynda! I'm off to test it out now. :)

6 | kristine

May 16th, 2002 at 1:19 pm

Avatar

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 :)

7 | Lynda

May 16th, 2002 at 1:26 pm

Avatar

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.

8 | Tricia

May 16th, 2002 at 1:33 pm

Avatar

*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…. 😀

9 | Tricia

May 16th, 2002 at 1:36 pm

Avatar

Ooops, I meant to say Amy's popup script and the random blog link script from HERE heh :)

10 | Lynda

May 16th, 2002 at 1:36 pm

Avatar

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.

11 | Tricia

May 16th, 2002 at 1:40 pm

Avatar

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.

12 | Lynda

May 16th, 2002 at 1:43 pm

Avatar

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' ?>

:)

13 | Tricia

May 16th, 2002 at 2:31 pm

Avatar

*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.

14 | Tricia

May 16th, 2002 at 2:33 pm

Avatar

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*)

15 | Lynda

May 16th, 2002 at 2:39 pm

Avatar

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:

16 | Tricia

May 16th, 2002 at 2:47 pm

Avatar

Errrr…I don't have any such box to check?? Where is that??
I did put recent.php in the second box, though. Bleh.

17 | Lynda

May 16th, 2002 at 2:51 pm

Avatar

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?

18 | Tricia

May 16th, 2002 at 2:53 pm

Avatar

*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*

19 | Gina

May 16th, 2002 at 2:55 pm

Avatar

The second part was exactly what I was going to ask on the forum.. woohooo.. this is great! Thank you! :)

20 | Tricia

May 16th, 2002 at 2:57 pm

Avatar

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.

21 | kristine

May 16th, 2002 at 2:58 pm

Avatar

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!!!

22 | Row

May 16th, 2002 at 11:29 pm

Avatar

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!

23 | kristine

May 17th, 2002 at 9:12 am

Avatar

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 :)

24 | Brian

June 19th, 2002 at 11:36 am

Avatar

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.

25 | Brian

June 19th, 2002 at 11:49 am

Avatar

I just realized I should have said how my archives are laid out, they go like this:

archives/&ltMonth Abbreviation&gt&ltYear>/&ltDay&gt/then the entries for that day.

26 | dave

September 14th, 2002 at 1:28 am

Avatar

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?

27 | Mike M

November 3rd, 2002 at 2:00 am

Avatar

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!

28 | MichaelE

November 16th, 2002 at 7:26 pm

Avatar

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!

29 | bozzy

January 2nd, 2003 at 1:32 pm

Avatar

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

30 | Kristine

January 2nd, 2003 at 2:05 pm

Avatar

You could use the 2nd option of the script, and then the MTEntryLink would automatically know where your archives were by default. :)

31 | Beerhound

January 30th, 2003 at 4:40 pm

Avatar

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>

32 | Kristen

February 23rd, 2003 at 10:52 am

Avatar

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!

33 | Pat

March 3rd, 2003 at 4:04 pm

Avatar

See Beerhound's script above –
sort_order="descend"

34 | Gillian

June 4th, 2003 at 5:04 pm

Avatar

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!

35 | Gillian

June 5th, 2003 at 12:03 pm

Avatar

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.

36 | Koki

September 18th, 2003 at 2:08 am

Avatar

I am trying to use method (2), but I get the following message when I rebuild:

MT::App::CMS=HASH(0x8391a10) 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

37 | stef

September 23rd, 2003 at 2:37 pm

Avatar

thank you for your script it worked great on our site!

38 | Pablo

December 9th, 2003 at 6:10 am

Avatar

¿How can I filter my comments (the author of the blog) from that list?

Thank you!

39 | Blinger

February 18th, 2004 at 8:18 am

Avatar

Thank-you, this worked beautifully.

40 | ken

July 17th, 2004 at 6:56 pm

Avatar

Thanks so much for the script. Method 2 worked first time with dated archives.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements