|
楼主 |
发表于 2014-1-3 19:23:45
|
显示全部楼层
本帖最后由 hardrock 于 2014-1-3 19:27 编辑
WordPress不用插件如何调用热门日志http://www.bluehostdemon.com/how-to-get-most-viewed-post.html 2013-11-05
首先打开function.php,添加一段代码:
function simple_get_most_viewed($posts_num=10, $days=300){
global $wpdb;
$sql = “SELECT ID , post_title , comment_count
FROM $wpdb->posts
WHERE post_type = ‘post’ AND TO_DAYS(now()) – TO_DAYS(post_date) < $days
AND ($wpdb->posts.`post_status` = ‘publish’ OR $wpdb->posts.`post_status` = ‘inherit’)
ORDER BY comment_count DESC LIMIT 0 , $posts_num “;
$posts = $wpdb->get_results($sql);
$output = “”;
foreach ($posts as $post){
$output .= “n<li><a href= “”.get_permalink($post->ID).”" rel=”bookmark” title=”".$post->post_title.” (“.$post->comment_count.”条评论)” >”. $post->post_title.”</a></li>”;
}
echo $output;
}
其中 $posts_num=10, $days=300 是显示日志的数量和统计的天数,这里是指统计300天内最热门的10篇。
然后在你需要调用热门日志的地方插入- <?php simple_get_most_viewed(); ?>
复制代码
补充内容 (2014-1-4 13:25):
nRelate Most Popular该插件展示网站最受欢迎的文章。Use our widget in any widget area in your theme http://www.1888u.com/discuz/thread-1027467-1-1.html |
|