scriptygoddess

21 May, 2002

Most Commented on Entries

Posted by: Lynda In: MT hacks

UPDATE 3.29.04
Lynda has a updated version of this script. I'll leave the content of the post up – but go to her site for the most recent version of the script.

——————————————-

I went looking to see if there was a way to list the most commented on entries within Moveable Type. I know this is a standard Greymatter feature, but I couldn't figure anything out for Moveable Type. Granted, I may not have looked hard enough.

Here is a simple PHP solution. I'm just going to copy and paste the code, it's quite easily customizable if you know what's going on. When I get back I might detail this post a little more.

If you know of a way to do this automatically within Moveable Type, please let me know.

First you will want to create a new index template. Give it any name you'd like, but remember this name for later on. For demonstration purposes, we will pretend the file is named comments.inc.

Copy and paste the following code into the template body:

<?php

<MTEntries lastn="99999">$comments[<$MTEntryID$>] = <$MTEntryCommentCount$>;
</MTEntries>

<MTEntries lastn="99999">$entryinfo[<$MTEntryID$>] = "<$MTEntryTitle encode_html="1" encode_php="qq"$>|<$MTEntryLink$>|<$MTEntryDate format="%m.%d"$>";
</MTEntries>

?>

You can change the MTEntryDate format to however you wish it to display. Save it and rebuild the index files.

Then, open a text editor and paste the following into that, changing only the first two lines per your preference:

<?php

# This is the path to the comments.inc:
include("/home/user/public_html/blog/comments.inc");

# This is the number of results you want to show:
$results = 5;

array_multisort($comments, SORT_DESC, $entryinfo);
$i = 0;
do {
$entries = explode("|", $entryinfo[$i]);
$entry_title = $entries[0];
$entry_link = $entries[1];
$entry_date = $entries[2];

echo "<b>$comments[$i] comments</b>: <a href=\"$entry_link\">$entry_title</a> ($entry_date)<br/>";

$i++;
} while ($i<$results);

?>

Save this file under any name you wish, with a PHP extension. Example, comments.php.

You should now be able to include this file where you'd like on your blog using the following code:

<?php include("/home/user/public_html/blog/comments.php"); ?>

Make sure to change the path to correctly reflect the path to your comments.php

30 Responses to "Most Commented on Entries"

1 | Jennifer

May 21st, 2002 at 7:18 pm

Avatar

Cool! I like it!! Maybe when I have time (HAHAHAHA!!!) 😉 I'll implement that here!

2 | Jade

May 23rd, 2002 at 5:49 am

Avatar

Oh, muchy likey. Once I switch my journal over to MT, then I will do this. Eventually.

3 | dvg

May 28th, 2002 at 7:29 pm

Avatar

Wow! This kicks boo-tay. I've been trying to do something like this for a while now. I got it working on my main page in about 3 minutes. It adds a bit to the rebuild time, but not too much. Very cool! And I have never tried anything with PHP before, so I was quite thrilled to have it up and running so quickly. Thanks, girls!

4 | pluramon

July 10th, 2002 at 6:29 pm

Avatar

Nice idea.

PHP is my friend. Or would be if I could integrate it within MT. Any day-zero PHP and MT tutorials
out there? Nothing I add PHPwise works, including the great sounding script above. Rebuild for the eg above chokes thus:

Template 'comments.inc' does not have an Output File

what gives?

thanks in advance….

5 | Lynda

July 10th, 2002 at 6:32 pm

Avatar

Sounds like you didn't choose a file name for comments.inc In the box marked "Output file:" enter… comments.inc

6 | pluramon

July 10th, 2002 at 9:44 pm

Avatar

Thanks for your help lynda… Partial success ( !! ), I guess: php now doing …something:

comments: ()
comments: ()
comments: ()
comments: ()
comments: ()

hmm..not very informative but I've only got a test blog up with 4 articles in it and only two are commented; would that be the problem?

7 | David Melle

July 18th, 2002 at 1:48 pm

Avatar

Hello Goddesses,

Thanks for the tip!

I was looking for a way to do this and it literally took me 5 minutes to implement it.

Thanks you very much for sharing your scripts and intelligence!

Bye,

David Melle
dmelle@factsofisrael.com
http://www.FactsOfIsrael.com

8 | Simply Sara

July 25th, 2002 at 10:35 am

Avatar

Love it, totally, wonderful!

Is there a way to add the year though? Thanks for everything y'all do~

:)

9 | Simply Sara

July 25th, 2002 at 10:47 am

Avatar

Never mind, found it, silly me. :)

10 | Al-Muhajabah

December 6th, 2002 at 2:33 am

Avatar

This is a great little trick. I would like to also display the TopicIcon for each of the entries. How would I modify the PHP code to include this in the entry info and then display it?

11 | iced glare

December 20th, 2002 at 8:30 pm

Avatar

thanks girlie I got it !

12 | yosshi

March 7th, 2003 at 1:20 am

Avatar

hello,
I was using this script and everything was going well before.
Now, because of reasons i've never known, the script returns an error message, such as:
Warning: Argument 1 to array_multisort() is expected to be an array or a sort flag in /home/***/***/comments.php on line 6.

what can I do about this?

thanks.

13 | yosshi

March 7th, 2003 at 3:31 am

Avatar

sorry, it's all my mistake.
I read manual again and did it. it works well again.

sorry.

14 | Mikel

May 21st, 2003 at 4:01 am

Avatar

Hi!
Thanks for this trick but i can't get it running. I've donne everything but I can't see anything in my main index.
Do somebody knows what is happening?

15 | Jennifer

June 25th, 2003 at 10:14 pm

Avatar

I wouldn't mind using this with a second blog.

I thought that all I'd have to do is, in the comments.inc file, use a second set of the same commands, enclosed in MTOtherBlog tags (I have the plugin installed).

This didn't seem to work. The comments.inc file lists only the first blog, not the second.

I even tried making two comments.inc files and pulling them both into the comments.php. That didn't do anything useful at all, though both .inc files showed their correct respective data.

Am I missing something here? Is there a modification I need to make to this somewhere else? Or is this just not a real possibility?

16 | Adam

June 29th, 2003 at 4:35 pm

Avatar

If you have Brad Choate's MTSQL installed, you can use this little bit of SQL to fetch the five most commented on stories:

SELECT comment_entry_id AS entry_id, COUNT(*) AS count FROM mt_comment WHERE comment_blog_id = 1 GROUP BY entry_id ORDER BY count DESC LIMIT 5;

(Note that comment_blog_id might differ slightly in your setup.)

17 | James

July 31st, 2003 at 7:07 am

Avatar

Can this feature be used if my archives in html instead of php? Thanks!

18 | Jennifer

July 31st, 2003 at 7:29 am

Avatar

Yes, but you would need to get your server to process your .html/.htm pages as if they were .php. See this post on how to do that.

19 | matt

September 12th, 2003 at 8:34 pm

Avatar

I've done everything, step by step. I've created the htaccess file because I use html. However nothing happens, no error message, no results, nothing. Help…

20 | Mindy

March 29th, 2004 at 2:02 pm

Avatar

I have installed everything according to the directions, but cannot get anything to show in the output file. If I view the output file in edit mode, I see all of the comment data, but nothing shows when I view the file. I have reviewed all of the working add-ons to see where the error is, but cannot find anything amiss. Any suggestions?

Thank YOU!!

21 | Jennifer

March 29th, 2004 at 2:24 pm

Avatar

Can you provide a link to the files you've created?

22 | Lynda

March 29th, 2004 at 7:11 pm

Avatar

Here is an updated version of this script using SQL and trackback information.

23 | Jennifer

March 29th, 2004 at 7:14 pm

Avatar

Cool! Thanks Lynda. I'll update the main post with your link :)

24 | SV

April 17th, 2004 at 7:36 am

Avatar

Thanks a million for the code. Now all I need to do is beautify.

25 | jim

May 7th, 2004 at 5:45 pm

Avatar

Hello,

I am trying to use your connect.php but not having any success. The following is a link to the message i am getting. Any help would be greatly appreciated. Thank you.
http://www.advancinginsights.com/testblog-1/most_commented.php

26 | SV

June 28th, 2004 at 4:03 pm

Avatar

I used this code and it worked like a song. And sent my comment with thanks too. Now mblog.com (where my blog is) decided not to allow php. Can you help me with pavascript code to do the same?? Please! Please!!

27 | brian

July 16th, 2004 at 11:54 pm

Avatar

I can't get the <?php include("http://www.bingwalker.com/blog/comments.php"); ?> to show anything on my page. My .inc file is here:
http://www.bingwalker.com/comments.inc
and my php file is here:
http://www.bingwalker.com/blog/comments.php

Any help on the error message with .php?

28 | brian

July 16th, 2004 at 11:55 pm

Avatar

I can't get the "php include" to output anything….. :(

29 | ***Dave Does the Blog

August 17th, 2004 at 11:44 am

Avatar

Commentary
Les links to today's Dork Tower on a topic important to most bloggers. Go ahead and read it … ……

30 | Jim Steed

February 1st, 2005 at 1:46 pm

Avatar

Before I saw your page, I wrote a MT Plugin that seems to do the same thing. It is available at
http://www.fakejazz.com/fake/archives/2005/02/movable_type_pl.php if anyone wants to try it out. Since it is a normal plugin, you wouldn't need PHP and it is context-sensitive to MTCategories, etc. I am using it to show the top 5 most commented on entries in each category. (Or maybe I should say "will be using it" since I just switched from hand-coding everything to MT and don't have many comments yet.)

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