php按时间归档,WordPress 按日期分类归档——按日期归档-帕兰映像

/*头部样式*/

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样式,按日期分类归档就完成了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值