function dp_recent_comments_ajax() {
$no_comments = 5;
$comment_len = 300;
global $wpdb;
$request = "SELECT * FROM $wpdb->comments";
$request .= " JOIN $wpdb->posts ON ID = comment_post_ID";
$request .= " WHERE comment_approved = '1' AND post_status = 'publish' AND post_password =''";
$request .= " ORDER BY comment_date DESC LIMIT $no_comments";
$comments = $wpdb->get_results($request);
if ($comments) {
foreach ($comments as $comment) {
ob_start();
?>
on comment_date; ?> :
'.__('No comments', 'my-first-wp-theme').'';
}
die(); // this is needed for ajax to work properly
}
function dp_get_author($comment) {
$author = "";
if ( empty($comment->comment_author) )
$author = __('Anonymous', 'my-first-wp-theme');
else
$author = $comment->comment_author;
return $author;
}
add_action('wp_ajax_my_recent_comments', 'dp_recent_comments_ajax');
add_action('wp_ajax_nopriv_my_recent_comments', 'dp_recent_comments_ajax'); //for users that are not logged in