我希望能够在我的主页上显示最近7天帖子的时间线。例如,如果今天是2013年1月1日,我希望我的博客提要显示如下内容:
2013年1月1日当天的所有帖子
2012年12月31日当天起的所有帖子
2012年12月30日当天的所有帖子
2012年12月29日当天的所有帖子
2012年12月28日当天的所有帖子
2012年12月27日当天的所有帖子
2012年12月26日当天的所有帖子
本质上,此提要应该始终显示7天的帖子。事实上,当1月2日到来时,12月26日就会被隐藏起来,一切都会被一个所撞。
这并不是我所希望的那样,因为当新的一周到来时,它只会显示1天的帖子,所以基本上,显示7天帖子的唯一一天是该周的第7天:
<section class="news-timeline">
<?php
$day_check = \'\';
$today = get_the_date();
$year = date(\'Y\');
$week = date(\'W\');
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\'=>\'post\',
\'category_name\' => \'whats-happening\',
\'year\' => $year,
\'w\' => $week,
\'paged\'=>$paged
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
if (function_exists(\'wp_pagenavi\')) { wp_pagenavi(); }
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
$day = get_the_date(\'j\');
if ($day == $today) {
echo "<h3>Today</h3>";
$counter = 0;
} elseif ($day != $day_check) {
echo "<h3>" . get_the_date() . "</h3>";
$counter = 0;
}
if ($counter % 3 == 0) {
$apply_css_margin = TRUE;
}
elseif ($counter % 3 == 1) {
$apply_css_margin = TRUE;
} else {
$apply_css_margin = FALSE;
}
$counter++;
?>
<article id="post-<?php the_ID(); ?>" <?php if($apply_css_margin) { post_class(\'news-timeline-margin\'); } else { post_class(); } ?>>
<a href="<?php the_permalink(); ?>">
<div class="meta">
<p class="author">By <?php the_author(); ?></p>
<p class="title"><?php the_title(); ?></p>
</div>
<?php the_post_thumbnail(\'homepage-features-news\'); ?>
</a>
</article>
<?php $day_check = $day; endwhile; endif; ?>
<!-- Older/Newer Pagination -->
<?php if ($wp_query->max_num_pages > 1) : ?>
<div class="pagination">
<?php next_posts_link(\'<span class="older ss-icon">←</span>previous\'); ?>
<?php previous_posts_link(\'Newer <span class="newer ss-icon">next</span>\'); ?>
</div>
<?php endif; ?>
<!-- /Older/Newer Pagination -->
<?php
if (function_exists(\'wp_pagenavi\')){wp_pagenavi();}
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
<!-- /Featured Loop -->
</section>