View Full Version : Display 'last comment' in wordpress?

03-03-2010, 09:09 AM
Hello, I'm hoping someone can help me with this.

On my main page of Wordpress I'm trying to make it so it displays the last posted comment under each article (single pages show all comments as usual, just talking about the main front page). An example would be here: http://destructoid.com/ where if you look underneath each article on the main page, it shows the last posted comment.


03-03-2010, 11:57 AM
You would use get_comment() along with is_home(). Check out the WP Codex for more info

03-03-2010, 06:27 PM
Hmm, it seems to be working but with one hiccup. It's displaying the "last post" made on the entire blog under each article. For example, my most recent article is about a video game, the last person to post says "Wow, that's cool!".. it shows "Wow, that's cool!" under all the other articles on the main page too, and not the last comment per each of those articles as I'm trying to do.

I feel close... almost there :thumbsup:

Edit: Basically I'm just trying to use this to do it.. but I guess it needs some sort of conditional to only make it for the article that it's current in while on the main page.

$comment_posts = get_option('woo_comment_posts');
if (empty($comment_posts) || $comment_posts < 1) $comment_posts = 1;
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved,
SUBSTRING(comment_content,1,50) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC LIMIT ".$comment_posts;
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
<?php echo get_avatar( $comment, '35' ); ?>

<a href="<?php echo get_permalink($comment->ID); ?>#comment-<?php echo $comment->comment_ID; ?>" title="on <?php echo $comment->post_title; ?>">
<?php echo strip_tags($comment->comment_author); ?>: <?php echo strip_tags($comment->com_excerpt); ?>...
<div style="clear:both"></div>

03-03-2010, 06:29 PM
Can you post your code? it sounds like you're passing either no ID or the wrong/same one

03-03-2010, 06:41 PM
Can you post your code? it sounds like you're passing either no ID or the wrong/same one

I edited and posted it above :)

03-04-2010, 06:39 AM
I guess there is no way to make this work? Still trying lol