Skip to content

Instantly share code, notes, and snippets.

@schalkburger
Created February 17, 2015 08:53
Show Gist options
  • Save schalkburger/b4e9ecc5d4b8e1e57da8 to your computer and use it in GitHub Desktop.
Save schalkburger/b4e9ecc5d4b8e1e57da8 to your computer and use it in GitHub Desktop.
Wordpress display comments
<?php // Display latest comments for each post on non-single page views
$comment_array = array_reverse(get_approved_comments($wp_query->post->ID));
$count = 1; // Number of comments to display
if ($comment_array) { ?>
<h3><?php comments_number('No comment', '1 comment', '% comments'); ?></h3>
<ul>
<?php foreach ($comment_array as $comment) {
if ($count++ <= 2) { ?>
<li><?php comment_author_link(); ?>: <?php comment_excerpt(); ?></li>
<?php }
} ?>
</ul>
<?php } else {
echo '<p>No comments yet.</p>';
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment