|
楼主 |
发表于 2014-1-3 19:23:57
|
显示全部楼层
本帖最后由 hardrock 于 2014-1-3 19:27 编辑
/ r6 r6 b4 I# a, V& j) Z% N$ B
) r% x6 {1 p( L- T. GWordPress不用插件如何调用热门日志http://www.bluehostdemon.com/how-to-get-most-viewed-post.html 2013-11-054 z) J7 j! a. i+ G5 }
; c$ C$ W% F# N8 ~* w) Q首先打开function.php,添加一段代码:
{) `$ \6 R9 i. {$ B; y* { function simple_get_most_viewed($posts_num=10, $days=300){+ b! w9 i6 z# r: R! N# x: R
global $wpdb;) B( B0 R5 Z0 A: \! _" }
$sql = “SELECT ID , post_title , comment_count
/ V. _( V. V- d6 U+ @7 w FROM $wpdb->posts
2 J4 J1 R4 R& } Q. q \ WHERE post_type = ‘post’ AND TO_DAYS(now()) – TO_DAYS(post_date) < $days: T3 K- _- |3 F0 a
AND ($wpdb->posts.`post_status` = ‘publish’ OR $wpdb->posts.`post_status` = ‘inherit’)
Q. G- H" ?1 g" W+ L$ k$ _6 V1 L ORDER BY comment_count DESC LIMIT 0 , $posts_num “;% c* p K8 r. V
$posts = $wpdb->get_results($sql);
6 o8 X* ?$ T7 d+ C $output = “”;5 [/ E/ s E. R0 h! U
foreach ($posts as $post){
5 U% f) Y7 _( j6 Z6 r $output .= “n<li><a href= “”.get_permalink($post->ID).”" rel=”bookmark” title=”".$post->post_title.” (“.$post->comment_count.”条评论)” >”. $post->post_title.”</a></li>”;$ Z/ d1 u/ l1 L- d5 Z9 N# }0 Y
}
( r3 p; S8 j: x2 p' | echo $output;2 [- a$ ~9 ~4 B/ N
} . G. Q0 ?8 |* b" b' ? r
其中 $posts_num=10, $days=300 是显示日志的数量和统计的天数,这里是指统计300天内最热门的10篇。 m9 S0 J( i7 c) k9 f: O! B
# X% S; S5 L% R. w
然后在你需要调用热门日志的地方插入- <?php simple_get_most_viewed(); ?>
复制代码 / ?* f- g2 @2 M3 ]
|
|