Unfortunately, the plugin API is geared more for actions upon posting, editing, commenting, etc; and falls a little short for actions to take when visitors load the page. The exception is wp_head, which may work for this instance.
You could make a hack pretty easily, though. All you need the following SQL query:
SELECT * FROM wp_comments
ORDER BY comment_date DESC LIMIT 5
You can use that in a php function as such:
<?php
$sql = "SELECT * FROM wp_comments ORDER BY comment_date DESC LIMIT 5";
$result = $wpdb->get_result($sql);
foreach ($result as $nonce) {
echo $nonce['Title'];
?>
I haven’t tested that yet, so it may not work; but the SQL query is functional (and tested).
Hmm, I think there’s more to it than just the wp_comments table. You’d need to reference the wp_posts tables as well to get the title. 😉
The easiest way (if you have WP 1.2 installed) is to go here:
http://mtdewvirus.com/wp-hacks/
Download the Plugins.zip file
Within the file are 5 plugins you can use. The plugin you want is probably recent-comments.php
Upload that file into wp-content/plugins
Then go into your control panel -> plugins
and activate Recent Comments
And in your index page, put
<? get_recent_comments(5, 7, ”, ‘
‘, true); ?>
where you want the list of new comments to be displayed. 🙂
Two problems with that solution:
1. There is no post title displayed.
2. If there were, there would probably be duplicates. Like two of the same post there.
If you want everything, use this SQL query:
SELECT DISTINCT * FROM wp_comments LEFT JOIN wp_posts on (wp_comments.comment_post_id = wp_posts.ID) ORDER BY wp_comments.comment_date DESC LIMIT 5;
How would that look in, say, the finished plugin file? Also, how exactly would I call it in the index.php file?
Sorry, I’m pretty darn new at this php stuff.