时光沉淀

wordpress归档页面

· Views · By 浪子

如果已有archives.php文件,我们直接打开修改其中内容即可,将一下代码复制进去:

<div class=archives>
<?php
$previous_year = $year = 0;
$previous_month = $month = 0;
$ul_open = false;
$myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');
foreach($myposts as $post) :
setup_postdata($post);
$year = mysql2date('Y', $post->post_date);
$month = mysql2date('n', $post->post_date);
$day = mysql2date('j', $post->post_date);
if($year != $previous_year || $month != $previous_month) :
if($ul_open == true) :
echo '</ul>';
endif;
echo '<h4 class=m-title>'; echo the_time('Y-m'); echo '</h4>';
echo '<ul class=archives-monthlisting>';
$ul_open = true;
endif;
$previous_year = $year; $previous_month = $month;
?>
<li>
<a href=<?php the_permalink(); ?>><span><?php the_time('Y-m-j'); ?></span>
<div class=atitle><?php the_title(); ?></div></a>
</li>
<?php endforeach; ?>
</ul>
</div>

不是全部复制哦,相信大家可以在archives.php文件中找到和以上代码一样以: 开头和

结尾的部分,替换这一部分即可。 剩下的就是加入css样式了,在style.css中加入下列代码即可,(dux或特别主题只需在后台自定义css样式中加入即可)

.archive-title{border-bottom:1px #eee solid;position:relative;padding-bottom:4px;margin-bottom:10px}
.archives li a{padding:8px 0;display:block}
.archives li a:hover .atitle:after{background:#428bca}
.archives li a span{display:inline-block;width:100px;font-size:12px;text-indent:20px}
.archives li a .atitle{display:inline-block;padding:0 15px;position:relative}
.archives li a .atitle:after{position:absolute;left:-6px;background:#ccc;height:8px;width:8px;border-radius:6px;top:6px;content:}
.archives li a .atitle:before{position:absolute;left:-4px;background:#fff;height:12px;width:12px;border-radius:6px;top:6px;content:}
.archives{position:relative;padding:10px 0}
.archives:before{height:95%;width:4px;background:#e6e6e6;position:absolute;left:100px;content:;top:30px}
.m-title{position:relative;margin:10px 0;cursor:pointer}
.m-title:hover:after{background:#ff5c43}
.m-title:before{position:absolute;left:94px;background:#fff;height:16px;width:16px;border-radius:8px;top:8px;content:}
.m-title:after{position:absolute;left:96px;background:#ccc;height:12px;width:12px;border-radius:6px;top:10px;content:}

评论

0 条评论

暂无评论

Using $this when not in object context

Error: Using $this when not in object context in /app/data/plugins/FediverseSync/template/comment.php:3 Stack trace: #0 /app/data/plugins/FediverseSync/Plugin.php(989): require_once() #1 [internal function]: FediverseSync_Plugin::renderComments(Object(Widget\Archive), NULL) #2 /app/var/Typecho/Plugin.php(446): call_user_func_array(Array, Array) #3 /app/var/Widget/Archive.php(1274): Typecho\Plugin->__call('Widget_Archive:...', Array) #4 /app/data/themes/paper-main/footer.php(23): Widget\Archive->footer() #5 /app/var/Widget/Archive.php(1336): require('/app/data/theme...') #6 /app/data/themes/paper-main/post.php(51): Widget\Archive->need('footer.php') #7 /app/var/Widget/Archive.php(1418): require_once('/app/data/theme...') #8 /app/var/Typecho/Router.php(99): Widget\Archive->render() #9 /app/index.php(23): Typecho\Router::dispatch() #10 {main}