So Very Posh

Thanks for visiting! This is the weblog of Lynda, a 26 year old girl living in Atlanta with her husband, three cats and two cockatiels.


All Comments By Author


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 comments by author and thought it would be neat to have as a link from everyone's posts instead of having to configure a page for each specific author. You can see how I've done this on my site. I thought I'd also share if anyone else is interested. Please be aware these instructions are for people who are rather familiar with Moveable Type and at least somewhat familiar with PHP.

Update: Found afterwards was the Virtual Venus description of making TGM's code dynamic. My long-winded post is more or less the same thing, but since I don't want to pass raw email addresses through the URL, I'll continue to use my way.

This requires two files.

One is connect.php which will have your database connection information. You may already have a file like this. TGM explains this better than I could, so I'll leave you on your own for that.

The second file will be the one which will have the users' comments on it. I named mine authorcomments.php. It needs to be a PHP file. I'd recommend first creating a file that matches your layout and leave the content areas blank to fill in with the required PHP code. We'll get to that file in a moment.

The first thing we want to do is prepare the comments to show the link. Go ahead and put the following in your templates before the </MTComments> tag, but don't rebuild yet:

<?php
$name = "<$MTCommentAuthor$>";
$email = "<$MTCommentEmail$>";
$blog = "<$MTBlogID$>";

$user = "$name||$email||$blog";
$user = urlencode(base64_encode($user));
?>

<a href="/path/authorcomments.php?user=<?php echo $user;?>">All <$MTCommentAuthor$>'s Comments</a>


Replace /path/authorcomments.php with the relative path of your authorcomments.php. Mine is /blog/authorcomments.php.

The rest of the code is gathering the user's information and the blog ID so that authorcomments.php can be used for any of your blogs if you wish. The information is put into a string, $user and then the string is encoded and is ready to be passed along to authorcomments.php

Save your template, we'll rebuild after you create authorcomments.php. At this point, you should have a file with the HTML for your layout and a place to put the content of the author's comments.

At the TOP of the file, you'll want to place this code:

<?php

//connection info
include ("/home/path/to/public_html/connect.php");

$user = urldecode(base64_decode($user));
$user = explode("||", $user);

$name = $user[0];
$email = $user[1];
$blog = $user[2];
?>


This has the path to your connection file. It also has information to DEcode the string we are passing along to the page.

After this code, in the body of your HTML file, you can place the following to note who the comments are from:

Comments by <?php echo $name;?>:


Finally, you'll want to place the following where you'd like the comments to show up:

<?php

if ($email != "" && $blog != "") {

$email=str_replace("@", "@", "$email");
$email=str_replace(".", ".", "$email");

$sql = "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 entry_id=comment_entry_id AND trackback_entry_id=comment_entry_id AND comment_blog_id='$blog' AND comment_email='$email' ORDER BY comment_created_on DESC";

$comments = mysql_query($sql);

$i = 1;

while($row = mysql_fetch_array($comments)) {
while (list($key,$val) = each($row)) {$$key = $val;}
$date = date("m/d/y h:i a", strtotime($comment_created_on));

$entry_title_link = "<a href="$trackback_url">$entry_title</a>";
?>

<b><?php echo $entry_title_link;?> at <?php echo $date; ?>:</b><br/><br/>
<?php echo $comment_text; ?><br/><br/>


<?php
$i++;
}
}
?>


This makes sure the database won't be queried if no information has been passed along to the page.

You can customize the bold information to suit your design. Just use <?php echo $VARIABLE; ?> where you want the information to go.

If you want to use alternating colors like I do, you can put in the following:

<div class="<? echo $i % 2 ? "style1" : "style2" ?>">


If it will help any, here is a copy of my complete authorcomments.php file.

Please let me know if there are any questions.

Comments

Comments are closed for this entry
Trackback: show all comments by an author
Update 3/26: In place of girlie's script, I'm using this variation by Lynda of So Very Post. It encodes the author's email address. I had been hiding it with the MTObfuscate plugin but I didn't feel very comfortable about making...
Tracked on: : Al-Muhajabah's Movable Type Tips on 03/26 at 06:55 PM
Trackback: MT Commenter Totals
MT Commenter Totals...
Tracked on: : Broad Bits on 03/28 at 06:29 PM

I’ve been watching your site and I think you’ve done a beautiful job.

I’m a newbie, am taking a blogging course through IWA-HTML and it is only 4 weeks and it is so packed full of information…

Anyway, I am having difficulty with TrackBack and I sent a ping to you (actuallyl, I hope you didn’t get it, would be embarassing) and the only resource I have is http://www.movabletype.org/trackback/beginners/. I am not sure where to put the code, what to do, or if I have it right.

Anything you can add?

&lt/kathy&gt

Posted by kathy painter on 04/08 at 02:51 PM | Link

I’m not sure it’s possible on blospot, Kathy.  To be honest with you, I’ve had little experience setting up trackback as a stand-alone application.  MT comes with it bundled, so I don’t need to know how to get it to work, it just does.

Posted by Lynda on 04/09 at 06:58 AM | Link