web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

wordpress如何只显示评论数量显示前100名的用户

271 ℃
     

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建站如何利用mysql语法批量插入文章

wordpress搭建视频网,视频加载慢怎么解决

wordpress如何实现版本回退

wordpress如何在文章标题上显示置顶标签

wordpress如何在二级目录建站(小编亲测有效)

标签: wordpress建站, 评论数量

上面是“wordpress如何只显示评论数量显示前100名的用户”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3339.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > wordpress
本文共计910个字,预计阅读时长7分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一个免费可商用psd文件素材网站——FreePik
下一篇: 一行代码轻松实现优雅的过渡动画插件——AutoAnimate
x 打工人ai神器