WP-PostViews 是一款統計 WordPress 網站文章瀏覽量的外掛,大家都喜歡用這個 WordPress 外掛統計每篇文章的閱覽量/點選率。但 WP-PostViews 只能統計所有時間內部落格文章的點選量,如果想要顯示最近一個月或者最近一週內博文熱門文章排行榜的話,WP-PostViews 暫時無能為力。
如果 WordPress 網站已經啟用了 WP-PostViews 外掛,實現 WordPress 網站顯示近期釋出的熱門文章的功能也不難。
在 sidebar.php 上增加:
<?php
function mostmonth($where = 」) {
//獲取最近 30 天文章
$where .= 」 AND post_date > 『」 . date(『Y-m-d』, strtotime(『-30 days』)) . 「『」;
return $where;
}
add_filter(『posts_where』, 『mostmonth』); ?>
<?php query_posts(「v_sortby=views&caller_get_posts=1&orderby=date&v_orderby=desc&showposts=10″) ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href=」<?php the_permalink() ?>」 title=」<?php the_title() ?>」><?php the_title() ?></a></li>
<?php endwhile; ?>
<?php endif; ?>
以上程式碼根據每個 WordPress 使用主題的不同,可能需要稍微修改下程式碼,適應 WordPress 主題的顯示風格。