X

Recent Comments list extra data no plugin

Paste it as is in the desired location in your theme… Note that the complete snippet shows the comment author email which you might want to hide in order to respect their privacy.

Code Snippet:

<?php
$comments = get_comments( array(
        'number'    => 10, // set comments amount here
        'status'    => 'approve' // set comment type here
) );
 
foreach($comments as $eachComment){
 
// COLLECTION THE DATA AND SETTING VARIABLES
$commentID = comment_ID;
$commentAuthorEmail = $eachComment->comment_author_email;
$commentPostId = $eachComment->comment_post_ID;
$commentPostTitle = get_the_title( $commentPostId );
$commentPostUrl = get_permalink( $commentPostId );
$comment_sidebarnumber = get_comments_number( $commentPostId );
 
global $wpdb;
$userCommentCount = $wpdb->get_var('SELECT COUNT('.$commentID.') FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . $commentAuthorEmail . '"');
        echo    '<div style="border: 1px solid #ccc; padding: 10px;">';
        echo    '<ul style="margin: 0px;">';
        echo    '<li>Written By: '. $eachComment->comment_author .'</li>';
        echo    '<li>Commented to: <a href="'.$commentPostUrl.'">'. $commentPostTitle .'</a></li>';
        echo    '<li>Commented on: '. $eachComment->comment_date .'</li>';
        echo    '<li>Author Website: '. $eachComment->comment_author_email .'</</li>';
        echo    '<li>Author Email: '. $eachComment->comment_author_email .'</</li>';
        echo    '<li>Author has: '. $eachComment->comment_author .' responded '. $userCommentCount .' times in total</</li>';
        echo    '</ul>';
        echo    '<p style="padding: 10px;"><strong>'. $eachComment->comment_author .' כתב</strong>: '. $eachComment->comment_content .'</p>';
        echo    '</div>';
}
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!