Show last commentator in a specific post (2 posts)

  1. Puanthanh Gangmei
    Posted 5 years ago #

    Like in BBPress I want to show the last commentator name and avatar of a post.

    This is for my discussion forum using CPT

    Please help

  2. Puanthanh Gangmei
    Posted 5 years ago #

    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' ); ?>
    <div class="poster-name">
    <a href="<?php echo get_permalink($comment->ID); ?>#comment-<?php echo $comment->post_ID; ?>" title="on <?php echo $comment->post_title; ?>">
    		<?php echo strip_tags($comment->comment_author); ?>:
    <div style="clear:both"></div>

    This code override other commentators in the post list

Topic Closed

This topic has been closed to new replies.

About this Topic