Wordpress Comments Loop


/ Published in: PHP
Save to your folder(s)

Just the basic Wordpress comments loop.


Copy this code and paste it in your HTML
  1. <!-- recent comment of each post -->
  2.  
  3. <div class="recent-comment">
  4. <?php
  5. $comment_array = array_reverse(get_approved_comments($wp_query->post->ID));
  6. $count = 1;
  7. ?>
  8.  
  9. <?php if ($comment_array) { ?>
  10. <span class="comment"> <?php comments_number('No comment','1 comment','% comments'); ?></span> - Latest by:
  11. <ul class="commentlist">
  12. <?php foreach($comment_array as $comment){ ?>
  13. <?php if ($count++ <= 2) { ?>
  14. <li><?php comment_author_link(); ?> <br /> <?php comment_excerpt(); ?> </li>
  15. <?php } ?>
  16. <?php } ?>
  17. </ul>
  18. <?php } else { ?> <!-- if there was no comment in that post,yet -->
  19. <span class="comment">No comment so far</span>
  20. <?php } ?>
  21. </div>
  22.  
  23. <!-- end recent comment-->

URL: http://warrenonline.ca

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.