每天显示帖子

时间:2016-01-26 10:12:20

标签: php wordpress

目前我的代码如下所示。

<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
<a class="vissted" href="<?php the_permalink(); ?>">
<div class="hovereffect">
<div class="thumbnail">
<?php the_post_thumbnail('singles', array( 'class'  => "img-responsive")); ?>
<div class="overlay">
<h2><?php the_title(); ?></h2>
</div>
<div class="caption">
<div class="ratings">
<p class="pull-right"> </p>
<p>
Watch Video
</p>
</div>
</div>
</div>
</div>
</a>
</div>     

<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php wp_reset_query(); ?>

此代码只显示我网站上的每条帖子,这很酷,但我希望将它提升到一个新的水平。我怎样才能使它显示每天的帖子,例如。

enter image description here

您会在顶角看到它显示帖子的日期,我很乐意在我的网站上执行此操作,然后将其限制为1周,但会将每个结果显示在新的块中。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在wordpress查询中,您应该添加所需的日期:

$current_month = date('m');
$current_year = date('Y');
$current_day = date('d');
$my_query = new WP_Query((array('year'=>date('Y'),'monthnum'=>date('m'),'day'=>date('d'),'posts_per_page'=>-1 ));

您可以随时更改current_month,current_year,current_day变量。