简约WordPress时间轴归档模板

这个时间轴在之前的基础上重新美化了一下,弄了些背景图上去,打造一把伞的样子,顶部一个中等图,一个父亲拉着他女儿的故事,同时也更改了页脚的背景,挺喜欢这风格的。

一、先准备几个图片,放在主题 assets/images/目录下,图片可以自己去设计或到网上找,也可以直接复制本站的。

二、新建一个 PHP 文档,把以下代码全部复制保存到主题 page/目录下

  1. <?php 
  2. /**
  3.  * Template Name: 时光轴
  4.  */
  5. get_header();?>
  6. <style>
  7. #footer{display:none}
  8. /*外框样式*/
  9. .archives {
  10. position:relative;
  11. padding: 200px 0 220px;margin-bottom:10px;
  12. min-height: calc(100vh - 70px);
  13. width: 750px;
  14. left:calc(50% - 375px);
  15. text-align: center;font-family: Georgia,'Microsoft JhengHei','微软雅黑';
  16. background: url(<?php echo get_template_directory_uri()."/assets/images/xtimebt.png" ?>) no-repeat left 328px bottom 0;
  17. }
  18. .diy-logo img{
  19. position: absolute;
  20. top:80px;
  21. left:50%;transform:translateX(-50%);border-bottom: 4px solid #86544D;max-width:90vw;z-index:2
  22. }
  23. .archives .diy-bt img{
  24. position: absolute;
  25. bottom:0px;
  26. left:328px;
  27. z-index:-1;
  28. }
  29. .archives ul{margin: 0;padding: 0}
  30. .diy-logo:hover {cursor: pointer}
  31. .archives>ul>li{
  32. list-style-type: none;
  33. position: relative;
  34. width: 100%;
  35. }
  36. .archives li a {
  37. padding: 8px 0;
  38. display: inline-block;
  39. color:#666;
  40. }
  41. /*标题前小圆点在鼠标经过时的样式*/
  42. .archives li a:hover .sp3{
  43. background: #ff5c43;
  44. }
  45. /*日期样式*/
  46. .archives li a .rq {
  47. position: absolute;
  48. left:275px;
  49. width: 100px;
  50. font-size: 14px;
  51. font-family: times;
  52. }
  53. /*标题*/
  54. .archives li a .atitle {
  55. position: absolute;
  56. left:388px;
  57. text-align: left;
  58. }
  59. /*标题前的外围小点*/
  60. .archives li a .sp4 {
  61. position: absolute;
  62. left: 367px;
  63. background: #86544D;
  64. height: 16px;
  65. width: 16px;
  66. border-radius: 50%;
  67. top: 10px;
  68. transition: all .3s
  69. }
  70. /*标题前的小点内围*/
  71. .archives li a .sp3{
  72. position: absolute;
  73. left: 370px;
  74. background: #fff;
  75. height: 10px;
  76. width: 10px;
  77. border-radius: 50%;
  78. top: 13px;
  79. z-index: 1;
  80. transition: all .3s
  81. }
  82. /*时间中间线*/
  83. .archives:before {
  84. height: calc(100% - 205px);
  85. width: 4px;
  86. background: #86544D;
  87. position: absolute;
  88. left: 373px;
  89. content: "";
  90. top: 50px
  91. }
  92. /*左边月份标题*/
  93. .m-title {
  94. position: relative;
  95. width:140px;
  96. top:10px;
  97. left:305px;
  98. cursor: pointer;
  99. color:#86544D;
  100. font-size: 18px;
  101. border: 4px solid #86544D;
  102. padding: 3px 0;
  103. background: #fff;
  104. border-radius: 20px;
  105. transition: all .5s;
  106. font-family: Georgia;
  107. }
  108. /*鼠标经过大圆点样式*/
  109. .m-title:hover{
  110. background: #ff5c43!important;
  111. }
  112. .diy-card{
  113. width:320px;
  114. position: relative;
  115. left:402px;
  116. top:16px;
  117. text-align: left;
  118. box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.3);
  119. transition: all .3s;
  120. z-index: 3
  121. }
  122. .diy-card:hover .post-img img{transform: scale(2);}
  123. .diy-card .post .post-title {display: none;margin:-4px 0 -12px;}
  124. .diy-card .post-style-card .post-top-meta {display: none;margin-bottom: 10px;}
  125. .diy-card .post-style-card .post-time {margin-top:10px}
  126. .diy-card .post-style-card .post-img{margin:-10px -10px 0;overflow: hidden;padding: 0}
  127. .diy-card .post-style-card .post-img img{transition: all .5s ease-out}
  128. .diy-card .post-style-card .post-bottom {padding-top:0}
  129. .diy-card .post-style-card .post-meta-author {margin-bottom: 0}
  130. .diy-card .post-style-card .post-meta-author a span {width: auto}
  131. body{
  132. background: url(<?php echo get_template_directory_uri()."/assets/images/bgbottom.png" ?>) no-repeat center bottom 0/contain fixed,url(<?php echo get_template_directory_uri()."/assets/images/bg.png" ?>) no-repeat right 0 top 70px fixed,linear-gradient(90deg,rgba(255,165,150,0.3) 10%,rgba(0,228,255,0.35)) no-repeat;
  133. }
  134. .bg{position:fixed;top:0;left:0;right:0;bottom:0;z-index:-2}
  135. @media(max-width:767px){
  136. body{
  137. background:url(<?php echo get_template_directory_uri()."/assets/images/bgbottom.png" ?>) no-repeat center bottom 0/contain fixed, linear-gradient(90deg,rgba(255,165,150,0.3) 10%,rgba(0,228,255,0.35)) no-repeat;
  138. }
  139. .diy-card,.diy-card .post{box-shadow:none;}
  140. .archives{width: 100%;padding-top:150px}
  141. .diy-logo img{top:70px}
  142. .archives li a .rq{display: none}
  143. .diy-card{width: 310px;left: 220px}
  144. .diy-card .post-style-card .post-top-meta{display: block;margin: 0px 4px}
  145. .diy-card .post .post-title {display: block;margin:0px 4px -8px;}
  146. .archives li a .atitle{display: none}
  147. .diy-card .post-style-card .post-img{height: auto;max-height:148px;margin:0px 4px;overflow: hidden;padding: 0}
  148.                 .diy-card .post-style-card .post-img img{height:auto}
  149. }
  150. @media(min-width:768px){
  151. .m-title:nth-of-type(2n) {left:252px}
  152. .m-title:nth-of-type(2n+1) {left:358px}
  153. .archives li:nth-child(2n) .diy-card{left:28px;}
  154. .archives li:nth-child(2n) .rq{left:376px;}
  155. .archives li:nth-child(2n) .atitle{
  156. left:28px;
  157. text-align: right;
  158. width: 335px;
  159. overflow: hidden;
  160. white-space: nowrap;
  161. text-overflow: ellipsis;
  162. padding: 0;
  163. }
  164. }
  165. </style>
  166. <div class="container">
  167.             <?php if (have_posts()): ?>
  168.                 <?php while (have_posts()) : the_post(); ?>
  169.                     <article class="page-content">
  170.                         <?php the_content(); ?>
  171.                     </article>
  172.                 <?php endwhile;  ?>
  173.             <?php endif; ?>
  174. <div class="bg">
  175. <div id="birds-canvas-holder"></div>
  176. </div>
  177. <div class="diy-logo"><img src="<?php echo get_template_directory_uri()."/assets/images/time.png" ?>" alt="点击可展开或收缩"></div>
  178. <div class="archives">
  179. <?php
  180. $previous_year = $year = 0;
  181. $previous_month = $month = 0;
  182. $ul_open = false;
  183. $myposts = get_posts( 'numberposts=-1&orderby=post_date&order=DESC' );
  184. foreach ( $myposts as $post ):
  185. setup_postdata( $post );
  186. $year = mysql2date( 'Y', $post->post_date );
  187. $month = mysql2date('n', $post->post_date );
  188. $day = mysql2date( 'j', $post->post_date );
  189. if ( $year != $previous_year || $month != $previous_month ):
  190. if ( $ul_open == true ):
  191. echo '</ul>';
  192. endif;
  193. echo '<h4 class="m-title">';
  194. echo the_time( 'Y-m' );
  195. echo '</h4>';
  196. echo '<ul class="archives-monthlisting">';
  197. $ul_open = true;
  198. endif;
  199. $previous_year = $year;
  200. $previous_month = $month;
  201. ?>
  202. <li style="min-height: 40px;">
  203. <a href="<?php the_permalink(); ?>"><span class="rq"><?php the_time('Y-m-j'); ?></span>
  204.     <div class="atitle"><?php the_title(); ?></div><span class="sp3"></span><span class="sp4"></span></a>
  205.     <div class="diy-card">
  206.                         <?php get_template_part('template-parts/post/content-card'); ?>
  207.                 </div>
  208. </li>
  209. <?php endforeach; ?>
  210. </ul>
  211. <div class="diy-bt"><img src="<?php echo get_template_directory_uri()."/assets/images/timebt.png" ?>" alt="点击可展开或收缩"></div>
  212. </div>
  213. </div>
  214.     <?php get_sidebar(); ?>
  215.     <?php get_footer(); ?>
  216. <script src="https://icss.me/myweb/index/three.min.js"></script> 
  217. <script src="https://icss.me/myweb/index/CanvasRenderer.js"></script>
  218. <script src="https://icss.me/myweb/index/Projector.js"></script> 
  219. <script src="https://icss.me/myweb/index/TweenMax.min.js"></script> 
  220. <script src="https://icss.me/myweb/index/main-0a79fb13e7.min.js"></script>
  221. <script>
  222. $('.archives ul.archives-monthlisting' ).hide();
  223. //$('.archives ul.archives-monthlisting:first' ).show();
  224. //$('.archives .m-title:first').css('background','#DDC6C4');
  225. $('.archives .m-title' ).click( function () {
  226. $('.archives .m-title' ).css('background','#fff');
  227. $(this).next().fadeToggle('fast');
  228. $(this).css('background','#DDC6C4');
  229. return false;
  230. } );
  231.  
  232. $( '.diy-logo' ) . on( 'click', function ( e ) {
  233. e . preventDefault();
  234. if ( $( this ) . data( 's' ) ) {
  235. $( this ) . data( 's', '' );
  236. $('.archives ul.archives-monthlisting').show();
  237. } else {
  238. $( this ) . data( 's', 1 );
  239. $('.archives ul.archives-monthlisting').hide();
  240. }
  241. } );
  242. </script>

三、新建一个页面,模板就选刚才建好的模板就行。以下是效果图,如果你需要显示底部信息的放在,就把最上面的那一行:#footer{display:none} 去掉就行

© 版权声明
THE END
喜欢就支持以下吧
点赞0赞赏
分享
相关推荐
  • 暂无相关文章
评论 抢沙发