Display latest comments for each post in WordPress




Here is the quick WordPress function to fetch latest approved comments for each posts, Normally, WordPress displays comments on single post views via the comments.php => theme template file. But you can also easily display comments for each post on the landing page and other pages where you want to display just use following php code.

<?php 
$commentArr = array_reverse(get_approved_comments($wp_query->post->ID));
$count = 1; 
if ($commentArr) { ?>
	<h3><?php commentsNum('0 comment', '1 comment', '% comments'); ?></h3>
	<ul>
	<?php foreach ($commentArr as $comment) {
		if ($count++ <= 2) { ?>
		<li><?php comment_author_link(); ?>: <?php comment_excerpt(); ?></li>
		<?php }
	} ?>
	</ul>
<?php } else {
	echo '<p>No Comments..</p>';
} ?>