添加自定义的归档页面

方法来自zwwooooo的代码实现WordPress归档页面模板[WP原生函数篇],方法如下: 1.把下面函数复制到主题functions.php文件内最后一个?>前面: /* Archives list by zwwooooo | http://zww.me */ function zww_archives_list() { if( !$output = get_option('zww_archives_list') ){ $output = ' [[全部展开/收缩](#)] _(注: 点击月份可以展开)_ '; $the_query = new WP_Query( 'posts_per_page=-1&ignore_sticky_posts=1' ); //update: 加上忽略置顶文章 $year=0; $mon=0; $i=0; $j=0; while ( $the_query->have_posts() ) : $the_query->the_post(); $year_tmp = get_the_time('Y'); $mon_tmp = get_the_time('m'); $y=$year; $m=$mon; if ($mon != $mon_tmp && $mon > 0) $output .= ''; if ($year != $year_tmp && $year > 0) $output .= ''; if ($year != $year_tmp) { $year = $year_tmp; $output .= ' ### '. $year .' 年 '; //输出年份 } if ($mon != $mon_tmp) { $mon = $mon_tmp; $output .= '- '. $mon .' 月 '; //输出月份 } $output .= '- '. get_the_time('d日: ') .'['. get_the_title() .']('. get_permalink\(\) .') _('. get_comments_number('0', '1', '%') .')_ '; //输出文章日期和标题 endwhile; wp_reset_postdata(); $output .= ' '; update_option('zww_archives_list', $output); } echo $output; } function clear_zal_cache() { update_option('zww_archives_list', ''); // 清空 zww_archives_list } add_action('save_post', 'clear_zal_cache'); // 新发表文章/修改文章时 2.复制主题内page.php更名为archives.php,然后在顶端加入: 找到类似,在下面加入如下代码: 进wp后台添加一新页面,在右侧栏【页面属性】模板选择 archives 3. 给主题加载 jQuery 库,没有加载的,把下面这句扔到 functions.php 里面就行了。 wp_enqueue_script('jquery'); 或者在header.php中添加下面的代码: <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.4.2/jquery.min.js"></script> 4. jQuery 效果代码: jQuery(document).ready(function($){ //===================================存档页面 jQ伸缩 (function(){ $('#al_expand_collapse,#archives span.al_mon').css({cursor:"s-resize"}); $('#archives span.al_mon').each(function(){ var num=$(this).next().children('li').size(); var text=$(this).text(); $(this).html(text+' _( '+num+' 篇文章 )_'); }); var $al_post_list=$('#archives ul.al_post_list'), $al_post_list_f=$('#archives ul.al_post_list:first'); $al_post_list.hide(1,function(){ $al_post_list_f.show(); }); $('#archives span.al_mon').click(function(){ $(this).next().slideToggle(400); return false; }); $('#al_expand_collapse').toggle(function(){ $al_post_list.show(); },function(){ $al_post_list.hide(); }); })(); }); PS:不知道怎么写js文件调用的就直接打开 header.php 并找到 ,在其下面加上

  1. css根据需要写,不写也可以的。HTML结构: [[全部展开/收缩](#)] _(注: 点击月份可以展开)_ ### '年份 - 月份 _(本月文章数量)_ - 号数: [文章标题](文章链接) _(评论数量)_ 到这里就OK了。感谢 zwwooooo大师!

添加自定义的归档页面
https://i.mraaaa.com/2015/01/13/添加自定义的归档页面/index/
作者
Mr.A
发布于
2015年1月13日
许可协议