wordpress如何获取评论数量显示前100名的用户,下面wed建站小编给大家详细介绍一下具体实现代码!
1、打开当前主题functions.php文件,新增以下代码:
function top_comment_authors($amount = 100) {
global $wpdb;
$prepared_statement = $wpdb->prepare(
'SELECT
COUNT(comment_author) AS comments_count, comment_author, comment_author_url, MAX( comment_date ) as last_commented_date
FROM '.$wpdb->comments.'
WHERE comment_author != "" AND comment_type = "" AND comment_approved = 1
GROUP BY comment_author
ORDER BY comments_count DESC, comment_author ASC
LIMIT %d',
$amount);
$results = $wpdb->get_results($prepared_statement);
$output = '<ul class="top-comments">';
foreach($results as $result) {
$output .= '<li class="top-comment-author"><strong> <a href="'.$result->comment_author_url.'" target="_blank" rel="external nofollow">'.$result->comment_author.'</a></strong> 共'.$result->comments_count.' 条评论,最后评论 '.human_time_diff(strtotime($result->last_commented_date)).'前</li>';
}
$output .= '</ul>';
echo $output;
}
2、页面调用代码:
<?php top_comment_authors(100); ?>
上面是“wordpress如何只显示评论数量显示前100名的用户”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3339.html
workflows工作流
一个黄色的海绵宝宝ComfyUI工作流
一碗热气腾腾的拉面ComfyUI工作流
小孩手握锤子顽皮搞笑卡通3d形象
森林里一只邪恶的树妖ComfyUI工作流
一个戴着破旧莎草帽的机械忍者
一座精致透明的白瓷人物雕塑comfyui工作流
强大的长袍法师ComfyUI工作流
一种长着彩虹翅膀的虫子comfyui工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

js+css3做一个灯泡开灯关灯效果
barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
css3做一个风雨雷电天气动态图标
3d文字360度旋转
自动打字效果(惊喜在后面)
css3搭积木叠加图形
canvas黑洞漩涡(canvas+js)











