• Pssst. Over here…

    Are you enjoying what you are reading? I hope so. If you do please take a second to subscribe to my RSS feed. Thank you for visiting my site. If you would like to know more about Adrian3 be sure to check this out. Oh, and you should probably follow me on Twitter if you aren't already...





  • Flickr
    Facebook
    LastFM
    Netflix
    Flickr
    YouTube




    Top Commener Movable Type Plugin

    I while back I added a new feature to Be A Design Group that created a list of the top commenters on our blog with a comment count next to the name of the comment author. It seems like it would be a native feature of Movable Type, but it isn’t. In my search for a plugin that could do the job I found some conversations about plugins called “CommentLeaders” and “mt-leaderboard”. The plugin were no longer listed on Movable Type’s plugin directory, and they don’t seem to be available anywhere else online.

    Finally I found a thread on Six Apart’s community forum that eventually led to the comment leader board plugin. The conversation wanders through several suggestions and improvements, but there isn’t a clear cut solution. I thought I would attempt to save you some work by explaining the solution that worked for me. I know just enough to make this work, so I apologize in advance for not being able to improvise beyond the following steps. Here it goes:

    The first step is to create a page called “connect.php” that will be used to access your Movable Type database. In a text editor, create a file with the following code:

    <?
    // name of your database
    $database = "databasename";

    // connect to database
    $db = mysqlconnect("localhost", "dbuser", "dbpassword")or die ('I cannot connect to the database.');
    mysql
    select_db("$database",$db);
    ?>

    Be sure to change databasename, dbuser, and dbpassword to your specific info. Save and upload to your server as connect.php.

    Next create a php page called “leaderboard.php” with the following contents:

    <? include 'connect.php';

    $leaders = mysqlquery("SELECT commentemail, commenturl, commentauthor, COUNT(*) as commentcount FROM mtcomment WHERE (commentblogid=1) AND (commentauthor!='name to exclude') AND (commentauthor!='another name to exclude') GROUP BY commentauthor ORDER BY commentcount DESC LIMIT 10");

    while($row = mysqlfetcharray($leaders)) {
    while (list($key,$val) = each($row)) {$$key = $val;}

    if (!empty($commenturl)) {
    $authorlink = "<a href=\"$comment
    url\">$commentauthor</a>";
    } elseif(!empty($comment
    email)) {
    $authorlink = "$commentauthor";
    } else {$authorlink = $comment
    author;}

    echo "$authorlink ($comment_count)<br />\n";
    } ?>

    There are a couple things to notice. First make sure that you have the correct path to your “connect.php” file. Next, you can exclude commenters from your list by replacing “name to exclude” with the name of the author who’s comments you don’t want to appear in the list. This is very helpful because if you are active in the comments of your blog you are probably the top commenter.

    If your blog id is not 1, change “blog_id=1” to reflect the blog id number of the blog you are adding the leader board to. Another thing to notice is that this will link the commenter’s name to the url they entered when they made a comment. If no web address was specified then their name will not be linked to anything. It would be simple to link the name to the email address of the commenter, but that would expose their email address to spammers and is probably not a good idea.

    Finally, at the spot in your blog where you would like the Leader-board to appear, add the following line:

    <!—#include virtual=”path/to/your/leaderboard.php” —> .

    If you are lucky, you now have a list of the top commenters on your blog. Like I said before, I just barely got this to work, so if you need help, you are pretty much on your own. If anyone decides to try this, and has suggestions about how to make this tutorial better, please let me know. Good luck!

    References: Six Apart’s community forum www.thegirliematters.com

    Switch to my mobile site