Пытаюсь выводить последние комментарии, с помощью плагина latest comments, комментарии и имя автора выводится, но ссылка на комментарий не правильная, то есть выводится ссылка на самую первую запись в блоге.
Версия вордпресса – 2.7.1
Записи выводятся не по ID, а названиям.
Вот код моего плагина:
<?php
function cypher_latestcomments($before='<li>', $after='</li>', $max_comments=5, $max_chars = 5) {
global $wpdb;
$gu=get_bloginfo('siteurl');
$output = '';
$request = "SELECT c.comment_post_ID, c.comment_author, c.comment_content, c.comment_date, p.post_status FROM $wpdb->comments c, $wpdb->posts p WHERE c.comment_post_ID = p.ID AND c.comment_approved = '1'";
$request .= " ORDER BY comment_date DESC LIMIT $max_comments";
$comments = $wpdb->get_results($request);
if($comments){
foreach ($comments as $comment){
$comment_post_ID = stripslashes($comment->comment_post_ID);
$comment_author = stripslashes($comment->comment_author);
$post_status = stripslashes($comment->post_status);
$comment_content = stripslashes($comment->comment_content);
$comment_content = str_replace('', '', $comment_content);
$comment_content = str_replace('', '', $comment_content);
$comment_content = strip_tags($comment_content);
$max_length = $max_chars;
$words = explode(' ', $comment_content, $max_length + 1);
if (count($words) > $max_length) {
array_pop($words);
array_push($words, '...');
$comment_content = implode(' ', $words);
}
$comment_date = stripslashes($comment->comment_date);
//$output .= $before . $comment_date . $after;
if ($post_status == 'static') {
$output .= $before . '<a href="' . clean_url( get_comment_link($comment->comment_ID) ) . '">' . $comment_author . '</a>: ' . $comment_content . $after;
} else {
$output .= $before . '<a href="' . clean_url( get_comment_link($comment->comment_ID) ) . '">' . $comment_author . '</a>: ' . $comment_content . $after;
}
}
}
echo $output;
}
?>
Подскажите пожалуйста в каком направлении мне действовать.
