1、桌面新建名为 my-archive.php 文件,写入如下代码
<?php/*Template Name: my-archive*/?> <span id="control" style="cursor:pointer;color:#666666;text-shadow:0 0 2px #66CD00;">全部展开/收起</span> <div><?php $previous_year = $year = 0; $previous_month = $month = 0; $ul_open = false; $myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC'); ?><?php foreach($myposts as $post) : ?><?php setup_postdata($post); $year = mysql2date('Y', $post->post_date); $month = mysql2date('n', $post->post_date); $day = mysql2date('j', $post->post_date);?> <?php if($year != $previous_year || $month != $previous_month) : ?> <?php if($ul_open == true) : ?></ul> <?php endif; ?> <h3><?php the_time('Y年 m月'); ?></h3><ul> <?php $ul_open = true; ?> <?php endif; ?> <?php $previous_year = $year; $previous_month = $month; ?> <li><span><?php the_time('m-d'); ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span><span> <?php if(function_exists('the_views')) { the_views(); } ?></span> <?php comments_popup_link( __( '评论 (0)', 'farlee' ), __( '评论 (1)', 'farlee' ), __( '评论 (%)', 'farlee' ), 'comments-link', __('评论关闭', 'farlee')); ?></li> <?php endforeach; ?></ul></div>
2、上传文件到 wordpress 使用的主题目录下,然后去后台新建“页面”,会发现有选择模板的选项:选择–>my-archive
3、写个页面名字,直接发表,不需要正文内容。
特别提示:懒得DIY的同学,可以使用这个 wp-easyarchives插件轻松完成归档页面制作。