Last active
September 3, 2018 10:26
-
-
Save amorkovin/22d3bb10650a6684586dbc57a3b370e5 to your computer and use it in GitHub Desktop.
Новые свежие комментарии в WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function src_simple_recent_comments($src_count=7, $src_length=60) { | |
global $wpdb; | |
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_date, comment_approved, comment_type, | |
SUBSTRING(comment_content,1,$src_length) AS com_excerpt | |
FROM $wpdb->comments | |
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) | |
WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' | |
ORDER BY comment_date_gmt DESC | |
LIMIT $src_count"; | |
$comments = $wpdb->get_results($sql); | |
if (!$comments) { | |
return false; | |
} | |
ob_start(); | |
foreach ($comments as $comment) { | |
# $date = apply_filters('the_time', mysql2date("j F, H:i", $comment->comment_date)); | |
?> | |
<li> | |
<a href="<?php echo get_permalink($comment->ID) ?>#comment-<?php echo $comment->comment_ID ?>"><?php echo $comment->post_title ?></a> | |
<p><?php echo strip_tags($comment->com_excerpt) ?>...</p> | |
<div class="name"><?php echo $comment->comment_author ?></div> | |
</li> | |
<?php | |
} | |
$new_comments = ob_get_clean(); | |
return $new_comments; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment