每日或每周热门帖子

时间:2016-03-14 16:25:06

标签: wordpress post widget

我想制作单独的热门帖子小部件,显示每日和每周流行,而不是一直显示热门帖子。

这是我的小部件代码

<?php $args = array(  'posts_per_page'  => $number,
'meta_key'     => 'post_views_count',
'orderby'      => 'meta_value_num',
'order'        => 'DESC',
'post_type'    => 'post',
'post_status'  => 'publish',
                                );
                    $query = new WP_Query( $args );
                    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
                       <article <?php post_class( 'cf' ); ?> role="article">
                            <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
                                <div class="masukin-gambar">
                                    <?php the_post_thumbnail('thumbnail'); ?><span class="iamoverlay"></span>
                                </div>
                                <h3 class="widget-title"><?php the_title(); ?></h3>
                            </a><h4 class="kategori-kecil"><?php printf( __( '%1$s', 'karatok' ), get_the_category_list(', ') ); ?></h4>
                            <span class="hitung-populer"><?php echo korankoran_get_post_views(get_the_ID()); ?></span>
                        </article>
                    <?php endwhile; endif; wp_reset_query();?>

1 个答案:

答案 0 :(得分:0)

post_views_count只是一个在每个视图上加1的计数。因此,无法使用该元数据执行您想要的操作,因为没有关于视图何时发生的记录。

有一个插件可以满足您的需求。我建议使用它,因为自己编写你的要求可能比它的价值更多。 https://wordpress.org/plugins/wordpress-popular-posts/