方案二:
1.这个方法比较简单,直接复制 一份主题的 page.php 更名为 archives.php,然后在最顶端加入:
<?php
/*
Template Name: archives
*/
?>
删除或注释下面代码,
<?php get_template_part( 'content', 'page' ); ?>
加入归档显示代码
<div class="entry-content">
<?php $the_query = new WP_Query( 'posts_per_page=-1&ignore_sticky_posts=1' ); //update: 加上忽略置顶文章
$year=0; $mon=0; $i=0; $j=0;
$all = array();
$output = '<div id="archives">';
while ( $the_query->have_posts() ) : $the_query->the_post();
$year_tmp = get_the_time('Y');
$mon_tmp = get_the_time('n');
//var_dump($year_tmp);
$y=$year; $m=$mon;
if ($mon != $mon_tmp && $mon > 0) $output .= '</div></div>';
if ($year != $year_tmp) {
$year = $year_tmp;
$all[$year] = array();
}
if ($mon != $mon_tmp) {
$mon = $mon_tmp;
array_push($all[$year], $mon);
$output .= "<div class='archive-title' id='arti-$year-$mon'><h3>$year-$mon</h3><div class='archives archives-$mon' data-date='$year-$mon'>"; //输出月份
}
$output .= '<div style="font-size:14px" class="brick"><a href="'.get_permalink() .'"><span class="time">'.get_the_time('n-d').'</span> '.get_the_title() .'<em>('. get_comments_number('0', '1', '%') .')</em></a></div>'; //输出文章日期和标题
endwhile;
wp_reset_postdata();
$output .= '</div></div></div>';
echo $output;
$html = "";
$year_now = date("Y");
foreach($all as $key => $value){
$html .= "<li class='year' id='year-$key'><a href='#' class='year-toogle' id='yeto-$key'>$key</a><ul class='monthall'>";
for($i=12; $i>0; $i--){
if($key == $year_now && $i > $value[0]) continue;
$html .= in_array($i, $value) ? ("<li class='month monthed' id='mont-$key-$i'>$i</li>") : ("<li class='month'>$i</li>");
}
$html .= "</ul></li>";
}
?>
<?php
wp_link_pages(
array(
'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ),
'after' => '</div>',
)
);
?>
</div><!-- .entry-content -->
2.然后 创建页面,选择 archives 页面模版,发布,OK了。
以上两种方法都可以实现,但个人建议方案一,既可以填写页面内容,也可以设置评论等其他功能!
页面: 1 2