下面就是WordPress获取最近24小时文章阅读数排行方法
<div id="wpgp_mostviewed-4" class="widget widget_wpgp_mostviewed clearfix">
<h3 class="widget-title">24小时热门阅读排行</h3>
<ul>
<?php
//新建查询数组
$args=array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
'after' => '1 day ago', //24小时内最新文章
),
),
'showposts'=>10, //文章数量
'meta_key' => 'views', //post_meta里文章阅读数统计字段名
'orderby' => 'meta_value_num',
);
query_posts($args);
?>
<?php if (have_posts()) :$i=0;?>
<?php while (have_posts()) : the_post();$i++;?>
<!--以下内容根据主题的实际情况作出修改即可-->
<li class="top10 clearfix">
<div class="image-frame">
<a class="post_link" href="<?php the_permalink() ?>" title="<?php the_title(); ?> <?php the_field('xiaoweiba'); ?>">
<span class="postthumb"><img rel="1" width="75" height="75" class="image-frame" src="<?php echo get_timthumb_src(75,75);?>" alt="<?php the_title(); ?> <?php the_field('xiaoweiba'); ?>"></span></a>
</div>
<div class="stories">
<h3 class="top-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?> <?php the_field('xiaoweiba'); ?></a></h3><br><?php the_time('Y年m月d日') ?> -
<span class="red"><?php if(function_exists('the_views')) { the_views(); } ?>°C</span>
</div>
<var><?php echo $i; ?></var>
</li>
<?php endwhile; wp_reset_query();//结束循环 ,重置查询
?>
<?php endif; ?>
</ul>
</div>
</div>