加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

wordpress获得最热文章(评论最多)两种方法

发布时间:2020-12-14 14:34:03 所属栏目:wordpress 来源:网络整理
导读:最热文章 能体现读者对文章的喜欢程度,让站长了解读者关注评论的程度,这里说的最热是以调取读者评论的数量为标准的。 方法1 $result = $wpdb-get_results("SELECT comment_count,ID,post_title FROM $wpdb-posts ORDER BY comment_count DESC LIMIT 0,10")

最热文章 能体现读者对文章的喜欢程度,让站长了解读者关注评论的程度,这里说的最热是以调取读者评论的数量为标准的。

方法1

$result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0,10");


foreach ($result as $post) {


setup_postdata($post);


$postid = $post->ID;


$title = $post->post_title;


$commentcount = $post->comment_count;


if ($commentcount != 0) { ?>




通过$wpdb->get_results直接读取数据库,并输出$commentcount(评论次数)。

方法2

$post_num = 10; // 设置调用条数

$args = array(

‘post_password’ => ”,

‘post_status’ => ‘publish’,// 只选公开的文章.

‘post__not_in’ => array($post->ID),//排除当前文章

‘caller_get_posts’ => 1,// 排除置顶文章.

‘orderby’ => ‘comment_count’,// 依评论数排序.

‘posts_per_page’ => $post_num

);

$query_posts = new WP_Query();

$query_posts->query($args);

while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读