WordPress 读者评论排行榜就是展示在本博客评论最多的几个读者的头像,通常也称为读者墙对用户来说是一个很好的体验,人气还算不错那么一定要加上排行榜墙展现读者,要是还没有多少人气的花也要加上读者墙鼓励读者多多访问,荒岛本次带来 WordPress 显示读者排行榜的教程,只要将下面的代码添加到主题的「functions.php」文件即可。
// 荒岛一座藏有宝藏的小岛
function top_comment_authors($amount = 98) {
global $wpdb;
$prepared_statement = $wpdb->prepare(
'SELECT
COUNT(comment_author) AS comments_count, comment_author, comment_author_url, comment_author_email, MAX( comment_date ) as last_commented_date
FROM '.$wpdb->comments.'
WHERE comment_author != "" AND comment_type not in ("trackback","pingback") AND comment_approved = 1 AND user_id = ""
GROUP BY comment_author
ORDER BY comments_count DESC, comment_author ASC
LIMIT %d',
$amount);
$results = $wpdb->get_results($prepared_statement);
$output = '<div class="top-comments">';
foreach($results as $result) {
$c_url = $result->comment_author_url;
$output .= '<div class="lx8"><div class="top-author ms bk da">';
if (get_option('cache_avatar')) {
$output .= '<div class="top-comment"><a href="' . $c_url . '" target="_blank" rel="external nofollow">' . begin_avatar($result->comment_author_email, 128, '', $result->comment_author) . '<div class="author-url"><strong> ' . $result->comment_author . '</div></strong></a></div>';
} else {
$output .= '<div class="top-comment"><a href="' . $c_url . '" target="_blank" rel="external nofollow">' . get_avatar($result->comment_author_email, 128, '', $result->comment_author) . '<div class="author-url"><strong> ' . $result->comment_author . '</div></strong></a></div>';
}
$output .= '<div class="top-comment">'.$result->comments_count.'条留言</div><div class="top-comment">' . human_time_diff(strtotime($result->last_commented_date)) . '前</div></div></div>';
}
$output .= '<div class="clear"></div></div>';
echo $output;
}
宝藏内容来自荒岛-https://x-imagine.com/wordpress-show-reader-leaderboard.html宝藏内容来自荒岛-https://x-imagine.com/wordpress-show-reader-leaderboard.html 请按「Ctrl+D」收藏荒岛分享给好友,如您发现本文教程或宝藏链接已失效,请联系站长修正!
荒岛公众号
扫一扫关注
HDsoft27
公众号ID已复制,前往微信关注...
荒岛哔哩姬
扫一扫关注
ximagine
哔哩姬ID已复制,前往B站关注...










