/*头部样式*/
div#header {background: url("images/bg.gif") repeat-x scroll left top transparent;border-bottom:1px solid #FFFFFF;height:226px;}
div#header .header-top{border-bottom:1px solid #CEEFFD;height:38px;}
div#header .header-top .logo{display:block;height:38px;float:left;width:400px;}
div#header .header-top ul.listpages{float:right;}
div#header .header-top ul.listpages li{float:left;margin-left:16px;line-height:38px;}
div#header .header-bottom{border-top: 1px solid #FFFFFF;}
首先新建一个名为:date-archive.php 按日期归档。
放入以下代码:
$query = $wpdb->get_results("SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts where post_type='post' and post_title !='自动草稿' GROUP BY YEAR(post_date) ORDER BY post_date DESC limit 0,12");
//$year_count = count($query);
foreach($query as $value){
setup_postdata($value);
//$postid = $year->ID;
$year = $value->year;
$sup_count = $value->posts;
?>
<?php echo $year;?> <?php echo $sup_count;?>
<?php //wp_get_archives(array('type' => 'monthly', 'limit' => '12','format' => 'html', 'before' => '','after' => '', 'show_post_count' => true,'echo' => 1));
$result = $wpdb->get_results("select MONTH(post_date) as monthly,count(ID) as posts from $wpdb->posts where post_type = 'post' and post_title != '自动草稿' and post_date like '$year%' group by MONTH(post_date) order by post_date limit 0,12");
//$month_count = count($result);
foreach($result as $m){
setup_postdata($m);
$month = $m->monthly;
$m_count = $m->posts;
?>
<?php echo $year.'年'.$month.'月';?> <?php echo $m_count;?>< ?php }?>
然后新建一个模板文件:date-page.php
在里面写入:
the_post();
get_template_part('date-archive','date-page' );
?>
这个是标题了:
记得在模板头部加上注释:
/*
Template Name: 按日期归档
*/
?>
为什么要这样加?这样加上注释后,WP系统为自动检测为模板文件,你在后台编辑页面时就可以选择该模板了。其他头部和底部还有样式我想你自己也可以完成了。
接着在后页面菜单里,新建一个页面保存后,然后点[快速编辑],选择模板。
点保存。
然后结合自己的网站风格修改相应的CSS样式,按日期分类归档就完成了。