制作WordPress时间轴文章列表

制作WordPress时间轴文章列表

作者 : 资源客 发布时间: 2019-12-6

今天给大家推荐的是一款时间轴样式的 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;
});

 

http://xzh.i3geek.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请不要用于商业用途及非法用途,否则后果自负!
3. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"qq301.com",如遇到无法解压的请联系管理员!
资源客是一个优秀的分享资源站,本站资源均为各位友友分享而来,特殊原创会标明如有侵犯版权等可联系删除

资源客 » 制作WordPress时间轴文章列表