本帖最後由 hardrock 於 2014-1-3 19:27 編輯 1 R/ l- I2 `' R* ]" l) v
% }- N! k; r! P5 ^/ zWordPress不用插件如何調用熱門日誌http://www.bluehostdemon.com/how-to-get-most-viewed-post.html 2013-11-05$ F- A, y, s8 L5 C8 h1 a) ^
2 Z2 G' s! y* J8 d$ k: d2 J$ L首先打開function.php,添加一段代碼:
( b4 W4 k5 s: B, ]* M$ s8 s function simple_get_most_viewed($posts_num=10, $days=300){
( h( ]2 i$ r' c; N* R! e P global $wpdb;
3 x* d. @* r- n! b3 u $sql = 「SELECT ID , post_title , comment_count
/ I- L5 v9 d6 M" a! H$ G FROM $wpdb->posts- t2 n* N! b) O6 _7 d
WHERE post_type = 『post』 AND TO_DAYS(now()) – TO_DAYS(post_date) < $days( l7 v, r% ^5 |5 d* b
AND ($wpdb->posts.`post_status` = 『publish』 OR $wpdb->posts.`post_status` = 『inherit』)" p) v- f2 @. u% w
ORDER BY comment_count DESC LIMIT 0 , $posts_num 「;. s/ j. U" W, `3 l9 o( i
$posts = $wpdb->get_results($sql);
, V( G1 u3 @& i8 ^7 | $output = 「」;
" c3 L6 D4 }5 K' a2 s foreach ($posts as $post){+ i4 Z; l H b( b3 B
$output .= 「n<li><a href= 「」.get_permalink($post->ID).」" rel=」bookmark」 title=」".$post->post_title.」 (「.$post->comment_count.」條評論)」 >」. $post->post_title.」</a></li>」;
- ]2 O: b" w5 l }+ U3 }) Z* n& ^% e
echo $output;: |+ M6 L8 i' G
} 0 @1 t/ `& z* Z# S
其中 $posts_num=10, $days=300 是顯示日誌的數量和統計的天數,這裡是指統計300天內最熱門的10篇。5 {8 y4 q- v" ~' l/ |: R
C! Q, K4 m- ]- b然後在你需要調用熱門日誌的地方插入- <?php simple_get_most_viewed(); ?>
複製代碼
( Y( s1 I+ i8 G" y2 e; ]; w1 e# r; D! L
/ ~: J% c3 n& z: E3 N
9 H' ^/ W, A( d J6 C* Y8 m8 U9 r補充內容 (2014-1-4 13:25):. V3 S* c% V! p% c$ B h) D0 \
nRelate Most Popular該插件展示網站最受歡迎的文章。Use our widget in any widget area in your theme http://www.1888u.com/discuz/thread-1027467-1-1.html |