前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WordPress免插件仅代码实现文章归档(模板页面)I

WordPress免插件仅代码实现文章归档(模板页面)I

作者头像
Jeff
发布2018-01-19 10:11:38
1K0
发布2018-01-19 10:11:38
举报
文章被收录于专栏:DeveWorkDeveWork

许多博友喜欢为自己的博客建立一个文章归档页面。WordPress 可以用插件来实现,但我们一贯遵守可以不用插件则不用的准则,现在Jeff 就为大家带来免插件仅代码实现文章归档的方法。效果见Jeff的阳台存档页。

关于WordPress 模板是什么自己去谷歌一下吧,注意不要将WordPress 主题跟模板混淆哦!

WordPress 免插件仅代码实现文章归档,coding!

新建一txt文件,打开输入如下代码:

<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 '</table>'; endif;   echo '<h3>'; echo the_time('F Y'); echo '</h3>'; echo '<table>'; $ul_open = true;   endif;   $previous_year = $year; $previous_month = $month; ?> <tr> <td width="40" style="text-align:right;"><?php the_time('j'); ?>日</td> <td width="400"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td> <td width="120"><a class="comm" href="<?php comments_link(); ?>" title="查看 <?php the_title(); ?> 的评论"><?php comments_number('0', '1', '%'); ?>人评论</a></td> <td width="120"><span class="view"><?php if(function_exists('the_views')) the_views(); ?>次浏览</span></td> </tr> <?php endforeach; ?> </table> </div>

在主题目录下的style.css中进入以下代码:

.archives td{padding: 6px 10px 8px;border-bottom: solid 1px #eee} .archives table{padding:10px 0 20px} .meta-tit{border-bottom: solid 1px #e6e6e6;padding: 0 0 10px;margin-bottom: 20px}

保存,将txt文件重命名为archives.php,注意不是archives.php.txt哦!然后在wordpress后台,页面-新建页面,题目任取,模板选择“存档”就可以实现了!

注意:

  • 上面代码中的<div id="main">等需要改为符合你的主题的选择器;
  • css样式需要自己修改以符合主题整体样式;
  • 如无特别情况,不建议使用该方法,更好的方法见下面的“建议”;

建议:

就Jeff 实践,该方法有很大的局限性,且是即时输出文章会,一旦文章过多,速度会有影响。不建议使用。更好的方法见下文更新。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013/02/23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • WordPress 免插件仅代码实现文章归档,coding!
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档