如何使用http://astheria.com/this-site/creating-a-timeline-style-archive-page (Demo for yearly archive)中的代码显示几个月而非一年的帖子?例如,我在2015年6月有3个帖子。2016年1月有2个帖子我想在月份对帖子进行排序。如下所示
这是年度存档的代码:
<?php get_header(); query_posts('posts_per_page=-1');
$dates_array = Array();
$year_array = Array();
$i = 0;
$prev_post_ts = null;
$prev_post_year = null;
$distance_multiplier = 2;
?>
<?php while (have_posts()) : the_post();
$post_ts = strtotime($post->post_date);
$post_year = date( 'Y', $post_ts );
/* Handle the first year as a special case */
if ( is_null( $prev_post_year ) ) {
?>
<h3 class="archive_year"><?=$post_year?></h3>
<ol class="archives_list">
<?php
}
else if ( $prev_post_year != $post_year ) {
/* Close off the OL */
?>
</ol>
<?php
$working_year = $prev_post_year;
/* Print year headings until we reach the post year */
while ( $working_year > $post_year ) {
$working_year--;
?>
<h3 class="archive_year"><?=$working_year?></h3>
<?php
}
/* Open a new ordered list */
?>
<ol class="archives_list">
<?php
}
/* Compute difference in days */
if ( ! is_null( $prev_post_ts ) && $prev_post_year == $post_year ) {
$dates_diff = ( date( 'z', $prev_post_ts ) - date( 'z', $post_ts ) ) * $distance_multiplier;
}
else {
$dates_diff = 0;
}
?>
<li style="margin-top:<?=$dates_diff?>px"><span class="date"><?php the_time('F j'); ?><sup><?php the_time('S') ?></sup></span> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php
/* For subsequent iterations */
$prev_post_ts = $post_ts;
$prev_post_year = $post_year;
endwhile;
/* If we've processed at least *one* post, close the ordered list */
if ( ! is_null( $prev_post_ts ) ) {
?>
</ol>
<?php } ?>
谢谢。 最好的问候。