时间:2021-07-01 10:21:17 帮助过:5人阅读
代码贴上,这段代码写在wp模板的function.php内。
function popularposts_with_comment($posts_num=10,$days=7,$display=ture) {
global $wpdb,$post;
$output = '';
$most_comment = $wpdb->get_results("
SELECT ID , post_title , comment_count
FROM $wpdb->posts
WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) < $days
ORDER BY comment_count DESC LIMIT 0 , $posts_num ");
foreach ($most_comment as $post) {
$post_title = get_the_title();
$post_views = getPostViews($postID);
$output .= '
'.get_the_post_thumbnail().''.
'
'.$post_title. '
浏览次数:'.getPostViews(get_the_ID()).'
';
}
echo $output;
}
想实现一个wordpress的热评文章(一定时间内,指定目录)功能,不想用插件,从网上找了很久,终于实现了2/3,为什么这么说,因为根据评论量排序和一定时间内这两个都实现了,但是指定目录这个还没实现。
代码贴上,这段代码写在wp模板的function.php内。
function popularposts_with_comment($posts_num=10,$days=7,$display=ture) {
global $wpdb,$post;
$output = '';
$most_comment = $wpdb->get_results("
SELECT ID , post_title , comment_count
FROM $wpdb->posts
WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) < $days
ORDER BY comment_count DESC LIMIT 0 , $posts_num ");
foreach ($most_comment as $post) {
$post_title = get_the_title();
$post_views = getPostViews($postID);
$output .= '
'.get_the_post_thumbnail().''.
'
'.$post_title. '
浏览次数:'.getPostViews(get_the_ID()).'
';
}
echo $output;
}