加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

制作WordPress时间轴文章列表

发布时间:2020-12-14 14:26:45 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 今天给大家推荐的是一款时间轴样式的 wordpress 文章归档页面,个人觉得比普通的归档页更加高大上一些,这里分享给大家,喜欢的可以拿去使用下。在 Wor

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

今天给大家推荐的是一款时间轴样式的 wordpress 文章归档页面,个人觉得比普通的归档页更加高大上一些,这里分享给大家,喜欢的可以拿去使用下。在 WordPress 中,文章归档页面是一个非常重要的页面,特别是当你的 wordpress 网站文章很多的时候,它将文章以年月日的分类方式对文章进行归类,可以让读者很方便的迅速找到某年某日的文章。wordpress 主题的文章归档页面样式大多是普通的文章标题列表页面,那今天给大家分享一组可以实现时间轴列表展示的文章归档页面代码,方便更清新的在页面中展示出标题及文章,且提供给大家前端的 css 及 js,而且有展开文章列表功能,体验与适配程度都比较好。

模板代码

<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 '<h3 class="m-title">'; echo the_time('Y-m'); echo '</h3>';

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>

CSS 样式

将 css 样式代码添加到 wordpress 主题和 style.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:#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:100px;content:"";top:0}

.m-title{position:relative;margin:10px 0;cursor:pointer}

.m-title:hover:after{background:#ff5c43}

.m-title:before{position:absolute;left:93px;background:#fff;height:18px;width:18px;border-radius:6px;top:3px;content:""}

.m-title:after{position:absolute;left:96px;background:#ccc;height:12px;width:12px;border-radius:6px;top:6px;content:""}

JS 特效

点击月份伸缩效果,放在 js 标签内部即可:

$('.archives ul.archives-monthlisting').hide();

$('.archives ul.archives-monthlisting:first').show();

$('.archives .m-title').click(function() {

$(this).next().slideToggle('fast');

return false;

});

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读