在wp\\u get\\u archives函数中,我能找到的唯一过滤器是用于显示链接的。基于get\\u archives\\u链接过滤器,这应该可以工作,在函数中使用它。php文件:
$archive_year = 0;
add_filter(\'get_archives_link\',\'wp_get_archive_grouped_by_year\',10,2);
function wp_get_archive_grouped_by_year($link_html) {
global $archive_year;
//Get the year from the link(probably better if you change this to regexp)
$year_new = explode(\' \', $link_html);
$year_new = explode(\'</a>\',$year_new[2]);
$year_new = $year_new[0];
$year_html = \'\';
//If the year is not display previously
if ($year_new != $archive_year) {
$archive_year = $year_new;
$year_html = \'<li class="year">\'.$archive_year.\'</li>\';
}
//Remove the year from the month link
$link_html = str_replace(\' \'.$archive_year, "", $link_html);
//Return the new links and exclude a specific year:
if($archive_year != \'2014\') {
echo $year_html.$link_html;
}
}
结果:
<li class="year">2014</li>
<li><a href=\'#\'>January</a></li>
<li class="year">2013</li>
<li><a href=\'#\'>November</a></li>
<li><a href=\'#\'>April</a></li>