Friday 21 July 2017

Display latest comments in wordpress template.

Display latest comments for each post in WordPress

<?php 
$commentArr = array_reverse(get_approved_comments($wp_query->post->ID));
$count = 1; // number of comments
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>';
} ?>

2 comments:


  1. Hello,

    we provide affordable and result-oriented SEO services, please give a chance to serve you.


    Thanks
    Admin: E07.net

    ReplyDelete
  2. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
    wordpress website

    ReplyDelete