最近有不少用户咨询如何根据评论数获取指定天数热评文章?今天为大家分享获取指定天数热评文章WordPress教程,希望能够帮助到需要的朋友。

将下方代码添加进functions.php外加一个php文件即可实现:

//获取指定天数热评文章

function most_comm_posts($days=7, $nums=10) {

global $wpdb;

$today = date(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”Y-m-d H:i:s\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”);

$daysago = date( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”Y-m-d H:i:s\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, strtotime($today) – ($days * 24 * 60 * 60) );

$result = $wpdb->get_results(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”SELECT comment_count, ID, post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’$daysago\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ AND \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’$today\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ORDER BY comment_count DESC LIMIT 0 , $nums\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”);

$output = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

if(!empty($result)) {

foreach ($result as $topten) {

$postid = $topten->ID;

$title = $topten->post_title;

$commentcount = $topten->comment_count;

if ($commentcount != 0) {

$output .= \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<li><a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’.get_permalink($postid).\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” title=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’.$title.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’.$title.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'</a> (\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’.$commentcount.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’)</li>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

}

}

}

echo $output;

}

//在需要调用的地方插入下方代码

<?php if(function_exists(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’most_comm_posts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’)) most_comm_posts

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部