tips and tricks for movable type

show all comments for comment author
January 04, 2004

This PHP/MySQL code will list all comments made by a particular comment author (based on their email address - if you allow anonymous comments, you'll need to modify the code to use another field).

Also, the script uses the Trackback URL for each entry commented on to provide a permalink to the entry. If your entries aren't Trackback-enabled, you may get strange results.

Update 04.15.04: The code has been updated to strip tags from comment text as a precautionary measure against malicious code.

<?
//connection info
include ("/path/to/your/connection/file/connect.php");

$author = 'girlie';
$email = 'girlie@thegirliematters.com';

$leaders = mysql_query("SELECT comment_url, comment_author, comment_text, comment_created_on, comment_entry_id, entry_title, trackback_url FROM mt_comment, mt_entry, mt_trackback WHERE (comment_blog_id=8) AND (comment_email='$email') AND (entry_id=comment_entry_id) AND (trackback_entry_id=comment_entry_id) ORDER BY comment_created_on DESC");

$email=str_replace("@", "&#64;", "$email");
$email=str_replace(".", "&#46;", "$email");
echo "Comments by <a href=\"$email\">$author</a>:<br /><br />\n";

while($row = mysql_fetch_array($leaders)) {
while (list($key,$val) = each($row)) {$$key = $val;}
$date = date("m.d.y", strtotime($comment_created_on));
$comment_text = strip_tags($row['comment_text']);
echo "posted $date on entry <a href=\"$trackback_url\">$entry_title</a>:\n";
echo "<blockquote>$comment_text</blockquote>\n";
}

?>

You must change /path/to/your/connection/file/connect.php to point to your connect file; change girlie and girlie@thegirliematters.com to match the comment author to display; and change 8 to match your blog ID.

You can also view a demo of the results (which is limited to 10 comments for the sake of brevity), and then read a tutorial at Virtual Venus on using the script dynamically for all comment authors.

Comments

Awesome... it worked! Thank you! :)

by Mariann | 01.05.04 07:26 PM

I am a total newbie when it comes to MT and I've tried to search for the code to the (permalink) on this line:

Posted by Name | Permalink | Comments | trackback

Do you have any idea where I can find that?? :-)

by Faith | 01.07.04 03:35 PM

Oh, I finally found it:-)

by Faith | 01.07.04 04:37 PM

I'm trying to implement this, but its output appears to strip most line breaks out of my commenters' posts.

I have MT set up to automatically generate <br> and <p> tags for commenters, like most MT users do. When my commenters want something fancier, like a <blockquote>, they enter it manually, and this script's output appears to respect that. But all the normal line breaks and paragraph breaks are gone.

Any suggestions for a user just starting to play with this PHP stuff?

by Patrick Nielsen Hayden | 02.02.04 07:50 PM

I am in a real bind!!!

I am a Java programmer who was given 3 days to build a php shopping site. Of course I had never programmed php..

Anyway, I am finishing it up today and I can't seem to get line breaks to fly in outlook, when I send out my emails. I get an error when I add '\n' or '\r\n' to my msg string. I have scoured the web searching for a solution and am still looking.

Please help, I have a client review in a few hours!

btw, this is a beautiful site, I love it.

Thanks,
Marq

by Donald Fagan | 03.01.04 08:16 AM

I use MBLOG.com for my blog, so do you think the SQL would work here? Please help

by SV | 04.20.04 06:00 PM

Took longer than it should have, but finally got it working on one of my sites. Thanks! PHP is not my forte and I've wanted to do something like this for awhile.

by Brian [TypeKey Profile Page] | 10.13.04 10:52 PM

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

TrackBack: 3
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/164)

» 20 things on My 2 Do list
Excerpt: 1. Add smilies in the comments 2. | Category | 3. Counting for (x) Recent entries 4. Statistics: " x entries", "x comments", "x users online", "x on this page" script 5. Last 50 referrers 6. 10 most commented entries7....
Weblog: .::faithjean.com::.
Tracked: 01.08.04 02:29 PM

» All Comments By Author
Excerpt: Now that I'm using Moveable Type again, I'm rediscovering all the cool things to do with it. The Girlie Matters' Tips and Tricks is a great site to get ideas! I was recently intrigued by her article on showing all...
Weblog: So Very Posh
Tracked: 03.19.04 11:54 AM

» Link to View All Comments for Comment Author
Excerpt: I posted an entry on my Tips Blog on how to show all comments for a particular comment author. In an effort to share the...
Weblog: Virtual Venus
Tracked: 04.15.04 11:34 AM