wordpress获得最热文章(评论最多)两种方法
最热文章 能体现读者对文章的喜欢程度,让站长了解读者关注评论的程度,这里说的最热是以调取读者评论的数量为标准的。 方法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(); ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |