Css打造伸缩时间轴样式的WordPress归档页面archive.php

archive.php文件 又称文章归档页面。在WordPress中,文章归档页面是一个非常重要的页面,特别是当你的wordpress网站文章很多的时候,它将文章以年月日的分类方式对文章进行归类,可以让读者很方便的迅速找到某年某日的文章。现在,很多博客,比如腾讯微博,QQ空间都有时间轴的显示方式,今天我们用也用时间轴的形式来记录显示我们的wordpress网站文章归档页面,并且加入伸缩功能。首先看看效果:

archive

1、在我们的主题更目录下建立archive.php(文章归档页面)
输入以下代码:

<?php
/**
 * The template for displaying archive pages
 * BootstrapWp 0.1
 */
get_header(); ?>
<div class="container">
<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></div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

由于主题是采用了Bootstrap框架所以加了,

<div class="container">

根据你自己的主题,可以选择适当的布局。
2、打开主题根目录下的style.css文件,加入以下css代码

/*
 * 文章归档页面样式
 */
.archive-title{border-bottom:1px #eee solid;position:relative;padding-bottom:4px;margin-bottom:10px} 
.archives li{list-style-type:none}
.archives li a{padding:8px 0;display:block}
.archives li a:hover .atitle:after{background:#ff5c43}
.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:8px;content:""}
.archives li a .atitle:before{position:absolute;left:-8px;background:#fff;height:12px;width:12px;border-radius:6px;top:6px;content:""}
.archives{position:relative;padding:10px 0}
.archives:before{height:100%;width:4px;background:#eee;position:absolute;left:130px;content:"";top:0}
.m-title{position:relative;margin:10px 0;cursor:pointer} 
.m-title:hover:after{background:#ff5c43}
.m-title:before{position:absolute;left:127px; background:#fff; height:18px;width:18px;border-radius:6px;top:3px;content:""}
.m-title:after{position:absolute;left:127px;background:#ccc;height:12px;width:12px;border-radius:6px;top:6px;content:""}

如果你引入以上CSS显示效果错乱的话,那么你就得调整上面的css布局了。
3、点击年月实现伸缩功能的话需要引入以下js

$('.archives ul.archives-monthlisting').hide();
$('.archives ul.archives-monthlisting:first').show();
$('.archives .m-title').click(function() {
    $(this).next().slideToggle('fast');
    return false;
});

 


如何你对Wordpress引入js有困惑的话,建议你阅读 WordPress引入css/js两种方法,如果你不想使用 伸缩功能的话,也可以采用分页的技术处理你的归档页面。


您可能感兴趣的文章:


▪ 利用Bootstrap构建你的响应式WordPress主题( 五)

▪ wordpress把JavaScript files 移动到HTML文档底部

▪ wordpress主题开发集成图像延迟加载

▪ 纯css实现指向图片放大

▪ 第三课511遇见WordPress主题开发教程基本文件的建立

▪ WordPress 快速添加友情链接的另类方法

▪ 第十课:wordpress主题制作主题布局

▪ Html5设计过程中必须遵循的几个原则

▪ wordpress限制非管理员访问管理面板

▪ WordPress函数:comment_form() 让你的 WordPress 评论表单随心所愿

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

511遇见

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值