经常有人问我wordpress根据浏览次数获取本周或本月热门文章怎么调用等等,今天呢就教下大家如何wordpress根据浏览次数获取本周或本月热门文章,具体根据自己实际情况来修改使用,因为代码并不一定百分百适应全部主题要修改查询字段。
wordpress获取一周热门文章排行
<?php
function mostweek($where = '') {
//获取最近七天的文章
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'mostweek'); ?>
<?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获取一月热门文章排行
<?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; ?>

