WordPress 热评文章实际上是指博客中评论最多的文章,而不是访问最多的文章,而自身的机制中每篇文章都已经记录了该文章的评论数目,所以只要通过评论数目排序就能轻松的找出评论最多的文章,荒岛本次带来 WordPress 显示热评文章的教程,只要将下面的代码添加到主题的「functions.php」文件即可。宝藏来自荒岛 - 一座藏有宝藏的小岛-https://x-imagine.com/wordpress-popular-comment-articles.html
// 荒岛一座藏有宝藏的小岛 function hot_comment_viewed($number, $days){ global $wpdb; $sql = "SELECT ID , post_title , comment_count FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND TO_DAYS(now()) - TO_DAYS(post_date) < $days ORDER BY comment_count DESC LIMIT 0 , $number "; $posts = $wpdb->get_results($sql); $output = ""; foreach ($posts as $post){ $output .= "\n<li class='hdicon'><a href= \"".get_permalink($post->ID)."\" rel=\"bookmark\" title=\" (".$post->comment_count."条评论)\" >".$post->post_title."</a></li>"; } echo $output; }宝藏来自荒岛 - 一座藏有宝藏的小岛-https://x-imagine.com/wordpress-popular-comment-articles.html
请按 Ctrl+D 收藏荒岛分享给好友 如您发现本文件已经失效无法下载请联系站长修正
- 荒岛公众号
- 扫一扫关注
- 荒岛小程序
- 扫一扫关注
评论