我在以下位置找到了部分答案:http://floatleft.com/notebook/wordpress-year-month-archives/
此解决方案显示所有有帖子的月份。甚至没有那么多代码:
<?php
$year_prev = null;
$months = $wpdb->get_results( "SELECT DISTINCT MONTH( post_date ) AS month ,
YEAR( post_date ) AS year,
COUNT( id ) as post_count FROM $wpdb->posts
WHERE post_status = \'publish\' and post_date <= now( )
and post_type = \'post\'
GROUP BY month , year
ORDER BY post_date DESC");
foreach($months as $month) :
$year_current = $month->year;
if ($year_current != $year_prev){
if ($year_prev != null){?>
</ul>
<?php } ?>
<h3><?php echo $month->year; ?></h3>
<ul class="archive-list">
<?php } ?>
<li>
<a href="<?php bloginfo(\'url\') ?>/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>">
<span class="archive-month"><?php echo date("F", mktime(0, 0, 0, $month->month, 1, $month->year)) ?></span>
</a>
</li>
<?php $year_prev = $year_current;
endforeach; ?>
</ul>
我的问题是,设计师添加了所有的月份,而不仅仅是那些有帖子的月份。我如何编辑它来显示所有月份,而不仅仅是有帖子的月份。我正在使用3.8.1谢谢