Title: Recent Comments Code
Last modified: August 20, 2016

---

# Recent Comments Code

 *  Resolved [lukehimselfnet](https://wordpress.org/support/users/lukehimselfnet/)
 * (@lukehimselfnet)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/recent-comments-code/)
 * Hi,
 * I want to put what appears on the default “Recent Comments” widget elsewhere 
   in my blog, on a non-widget area.
 * I’ve looked around and wasn’t sure how to locate the code? There’s some other
   code around for different Recent Comments, but I specifically want the default
   WordPress style.
 * My blog is lukehimself.net and I want to put it at the bottom in a <div>.
 * Thanks,
    Luke.

Viewing 1 replies (of 1 total)

 *  Thread Starter [lukehimselfnet](https://wordpress.org/support/users/lukehimselfnet/)
 * (@lukehimselfnet)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/recent-comments-code/#post-3625877)
 * I worked it out using this code, for anyone who searches the same thing.
 *     ```
       <?php
       $number=5; // number of recent comments desired
       $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
       ?>
       <ul id="recentcomments">
       <h2>Recent Comments</h2>
       <?php
       if ( $comments ) : foreach ( (array) $comments as $comment) :
       echo  '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a>comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '';
       endforeach; endif;?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Recent Comments Code’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [lukehimselfnet](https://wordpress.org/support/users/lukehimselfnet/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/recent-comments-code/#post-3625877)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
