如果你坚持展示所有的月份,我会做的是使用wp_get_archives
以自定义格式返回字符串,然后使用PHP DOMDocument 要解析它,请创建一个月数组,并添加那些还不存在的月份。
我认为这可能比你希望的要复杂一些,但这里有一个非常基本的例子:
$archives = wp_get_archives( array(
\'type\' => \'monthly\',
\'echo\' => 0,
\'format\' => \'custom\',
\'before\' => \'\',
\'after\' => \'\'
) );
$dom = new DOMDocument();
@$dom->loadHTML( "<?xml encoding=\'" . get_bloginfo( \'charset\' ) . "\'>" . $archives );
$xpath = new DOMXPath( $dom );
$months = $xpath->query( \'//a\' );
$months_array = array();
foreach( $months as $month ) {
$name_year = $month->nodeValue;
$link = $month->getAttribute( \'href\' );
$months_array[] = array( \'title\' => $name_year, \'url\' => $link );
}
unset( $xpath, $dom ); // Clean up
// Do something to add the months that don\'t exist to $months_array
// Possibly give them the \'#\' or \'javascript:;\' URL?
// Echo accordingly