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; ?>