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.
<?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>'; } ?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 7 best WordPress GDPR plugins to create a GDPR compliant site and how to create a WordPress donation form.
Comments Leave a Reply