I'd like to add a section to my footer that shows the last five comments posted. Does anyone know what kind of code I'd need for that? I've managed to put the last five posts in the footer thanks to the following code: <?php wp_get_archives('type=postbypost&limit=5'); ?> PHP: Would it be just a case of replacing "archives" with "comments"?
There is no wp_get_comments function, or any other function that can list them outside of the loop. You need to use one of the many plugins for recent comments. If you use Get Recent Comments, it gives you a new function to use: <?php get_recent_comments(); ?>
Cheers Dean! Hopefully, they will add it in the near future. I'm sure there is a lot of demand for it. They just added some new comment functions in 2.7, but not this one for some reason. BTW, found this code on the Wordpress forums that gets the last five comments. <?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 href="'. get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; endforeach; endif;?></ul> Code (markup):