1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 带时间轴的文章归档的html页面 Css打造伸缩时间轴样式的WordPress归档页面archive.php...

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

时间:2019-12-10 20:34:02

相关推荐

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

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

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

输入以下代码:

/**

* The template for displaying archive pages

* BootstrapWp 0.1

*/

get_header(); ?>

$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 '';

endif;

echo '

'; echo the_time('Y-m'); echo '

';

echo '

';

$ul_open = true;

endif;

$previous_year = $year; $previous_month = $month;

?>

<?php the_time('Y-m-j'); ?>

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

根据你自己的主题,可以选择适当的布局。

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两种方法,如果你不想使用 伸缩功能的话,也可以采用分页的技术处理你的归档页面。

您可能感兴趣的文章:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。