Die Kommentare liegen in einer eigenen Tabelle, die kannst Du mit einer Abfrage auf wp_posts nicht rauskriegen. Die bisherige Abfrage nutzt ja wp_posts, weil dort steht, wie viele Kommentare pro Beitrag vorhanden sind.
Aber mal ehrlich, man muss das Rad ja nicht immer neu erfinden. Plugins, die die letzten x Kommentare anzeigen, gibt es genügend. Oder Du verwendest eben eine fertige Funktion in Deiner functions.php. Ich benutze bei mir den folgenden Code (Achtung: Ohne jede Gewähr! Bei mir funktioniert's, aber wenn es bei Dir nicht geht, nimm vielleicht lieber das Plugin, auf dem das basiert):
/**
* Outputs the most recent comments. Based on the 'Recent Comments'
* plugin by Nick Momrik (http://mtdewvirus.com/code/wordpress-plugins/).
*
* @param argCommentNumber The number of comments to display.
* @param argTitle The title to display before the comment list.
* @param argShowPassPost True to show comments from password
* protected posts, false to omit them.
*/
function xy_the_recent_comments($argCommentNumber = 5, $argTitle = '', $argShowPassPost = false) {
global $wpdb;
// request the comments from the database
$request = "SELECT ID, comment_ID, comment_author, comment_date, post_title FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE post_status IN ('publish', 'static') ";
if (!$argShowPassPost) {
$request .= "AND post_password ='' ";
}
$request .= "AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT $argCommentNumber";
$comments = $wpdb->get_results($request);
// build the output
$output = '';
if ($comments) {
// append the title and start the list
if ($argTitle !== '') {
$output .= $argTitle;
}
$output .= "<ul>\n";
// append the comments
foreach ($comments as $comment) {
$commentAuthor = stripslashes($comment->comment_author);
if ($commentAuthor == "") {
$commentAuthor = "anonymous";
}
$permalink = get_permalink($comment->ID) . '#comment-' . $comment->comment_ID;
$postTitle = stripslashes($comment->post_title);
$commentDate = $comment->comment_date;
$commentDate = 'am ' . mysql2date('j. F Y \u\m H:i', $commentDate) . ' Uhr';
$output .= '<li><a href="' . $permalink . '" title="' . $commentDate . '">' . $commentAuthor . ' zu \'' . $postTitle . '\'</a></li>' . "\n";
} /* end for each comment */
// end the list and apply filters to the output
$output .= "</ul>\n";
$output = convert_smilies($output);
}
// write it to the page
echo $output;
}
Alles anzeigen