Comments php wordpress example template?

Comments php wordpress example template?

Here is the code that you can use in a wordpress template file to add comments.

1
2
3
4
5
6
7
8
9
10
11
<html>
<h3>Recent comments</h3>
<div style="font-size:15px">
<?php
$comments = get_comments('status=approve&number=5');
  foreach($comments as $comm) :?>
 
 <?php echo($comm->post_ID);?>
    <?php echo($comm->comment_author);?> - <a class="sidebar-links" href="<?php echo get_permalink($comm->comment_post_ID);?><?php echo get_the_title($comm->comment_post_ID);?></a><br /><br />
<?php endforeach;?>
</div>

This will display the name of the user who left the comment and the post with the link where the comment was made. You can add the date or whatever you like. Just need to look at the wordpress codex.

Add a comment: