试试这个,我应该澄清一下,代码是基于我看到的一个片段。
<?php
$blogtime = date(\'Y\');
$prev_limit_year = $blogtime - 1;
$prev_month = \'\';
$prev_year = \'\';
$args = array(
\'posts_per_page\' => 20,
\'ignore_sticky_posts\' => 1
);
$postsbymonth = new WP_Query($args);
while($postsbymonth->have_posts()) {
$postsbymonth->the_post();
if(get_the_time(\'F\') != $prev_month || get_the_time(\'Y\') != $prev_year && get_the_time(\'Y\') == $prev_limit_year) {
echo "<h2>".get_the_time(\'F, Y\')."</h2>\\n\\n";
}
?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php // your other template tags ?>
<?php
$prev_month = get_the_time(\'F\');
$prev_year = get_the_time(\'Y\');
}
?>