On 90% of my clients projects that are running WordPress I usually don’t run their Recent Comments anywhere on the site but in some rare cases they might actually want them. I was talking to my partner Greg today and he was wanting to do this on his site.
I had to stop and think what the calls were to do this since I rarely do this but I figured it might happen again someday so here is the code you can drop into your sidebar.php file on your theme to accomplish this.
<h2>Recent Comments</h2>
<?php
global $wpdb;
$sql = <span style="color: #006080">"SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT 10"</span>;
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= <span style="color: #006080">"\n<ul>"</span>;
<span style="color: #0000ff">foreach</span> ($comments <span style="color: #0000ff">as</span> $comment) {
$output .= <span style="color: #006080">"\n<li>"</span>.strip_tags($comment->comment_author)
.<span style="color: #006080">":"</span> . <span style="color: #006080">"<a href=\""</span> . get_permalink($comment->ID) .
<span style="color: #006080">"#comment-"</span> . $comment->comment_ID . <span style="color: #006080">"\" title=\"on "</span> .
$comment->post_title . <span style="color: #006080">"\">"</span> . strip_tags($comment->com_excerpt)
.<span style="color: #006080">"</a></li>"</span>;
 
}
 
$output .= <span style="color: #006080">"\n</ul>"</span>;
$output .= $post_HTML;
echo $output;?>




Pingback: Mutantfrog Travelogue » Blog Archive » Recent comments sort of back