Ta sẽ xuất danh sách như sau.
Các bạn thêm vào functions.php
.
function get_top_commenters($number = 10, $echo = true) {
global $wpdb;
$results = $wpdb->get_results('SELECT COUNT(comment_author_email) AS comments_count, comment_author
FROM ' . $wpdb->comments . '
WHERE comment_author_email != "" AND comment_approved = 1
GROUP BY comment_author_email
ORDER BY comments_count DESC, comment_author ASC
LIMIT ' . $number
);
$output = '<ol class="top-commenters">';
foreach ($results as $result) {
$output .= '<li>' . $result->comment_author . ' <span class="blue">– ' . $result->comments_count . ' bình luận</span></li>';
}
$output .= '</ol>';
if ($echo) {
echo $output;
}
return $output;
}
Để sử dụng, các bạn chỉ cần ghi như sau.
<h3 class="title">Những Người Bình Luận Nhiều Nhất</h3>
<div class="top-commenters-list">
<?php get_top_commenters(15); ?>
</div>
Với 15 là số lượng phần tử của danh sách.
Chúc các bạn thành công!
Bình Luận