我正在尝试创建一个帖子列表,每个月都有一个分隔符显示。
应该看起来像这样:
January 2018
- blog post
- blog post
Febuary 2018
- blog post
etc....
我正在使用的代码是一个简单的循环。我试图使用the_date()函数使分隔符工作并更改其日期格式。但它仍然每天触发。
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1
);
$the_query = new WP_Query($args); if($the_query->have_posts()): while($the_query->have_posts()): $the_query->the_post();
?>
<?php if(!the_date('F Y','','',false) == ''){ ?>
<div class="seperator">
<?php the_time('F Y'); ?> //echo month and year
</div>
<?php } ?>
<div class="post"> //the post content </div>
<?php endwhile; endif; wp_reset_query(); ?>
我真的不知道该用什么代码使它每个月触发一次。
答案 0 :(得分:0)
您应该尝试这样的事情:
>>> df
ap1_X as1_X ap2_X as2_X
0 1 1 2 6
1 2 4 2 6
2 3 9 2 6
3 4 16 2 6
这样,在每次迭代中,您都要在lastMonth变量中设置发布月份。在下一次迭代中,您正在检查发布的月份是否等于上一个月份。如果没有,则您处于新循环中,可以插入分隔符。