There’s this built-in function for querying comments get_comments
and here’s something that would help in your template:
$comments = get_comments( array( 'number' => 10 ) );
if ( !empty( $comments ) ) {
?>
<ul>
<?php foreach ( $comments as $comment ) : ?>
<li><?php echo sprintf(
"<strong>%s</strong> on <a href=\"%s\">%s</a> : \"%s\" — <a href=\"%s\">view</a>",
$comment->comment_author,
get_the_permalink( $comment->comment_post_ID ) . "#comment-" . $comment->comment_ID,
get_the_title( $comment->comment_post_ID ),
mb_strlen( $comment->comment_content ) > 100 ? mb_substr($comment->comment_content, 0, 100) . " .." : $comment->comment_content,
get_the_permalink( $comment->comment_post_ID ) . "#comment-" . $comment->comment_ID
); ?></li>
<?php endforeach; ?>
</ul>
<?php
} else {
echo sprintf("<p>%s</p>", "No comments were found.");
}
If you want a short-code or a custom function and needed help, comment below.
Hope that helps.