Moke|墨客

 找回密码
 立即注册
搜索
查看: 7354|回复: 0

WordPress教程:日志归档的设置

[复制链接]

3636

主题

0

回帖

3681

积分

超级版主

Rank: 8Rank: 8

积分
3681
发表于 2016-5-12 18:19:31 | 显示全部楼层 |阅读模式






                  大多数情况下WordPress博客为了更多地展示精彩文章,会在侧边小工具中添加一个基于日期的文章归档列表,不过这样不仅占用了侧边大块的空间,而且也不是很美观。下面的方法可以在不占用任何额外的空间的前提下,方便读者按年,月,日阅览日志文章,增加流量。
  一般的WordPress主题都会在显著的位置注明日志的发布或者修改日期,并没有什么实用价值,我们的目的就是将年,月,日连接到相应的存档页面。
  一,将下面的代码添加到主题functions.php模版的最后:
<?php   add_shortcode( 'entry-link-published', 'my_entry_published_link' );   function my_entry_published_link() {       /* 获取当前日志的年,月,日. */      $year = get_the_time( 'Y' );       $month = get_the_time( 'm' );       $day = get_the_time( 'd' );       $out = '';       /* 添加链接到年存档. */      $out .= '<a href=&quot;' . get_year_link( $year ) . '&quot; title=&quot;查看所有' . esc_attr( $year ) . '年文章&quot;>' . $year . '年</a>';       /* 添加链接到月存档. */      $out .= '<a href=&quot;' . get_month_link( $year, $month ) . '&quot; title=&quot;查看所有' . esc_attr( get_the_time( 'Y年m月' ) ) . '文章&quot;>' . get_the_time( 'm月' ) . '</a>';       /* 添加链接到日存档. */      $out .= '<a href=&quot;' . get_day_link( $year, $month, $day ) . '&quot; title=&quot;查看所有' . esc_attr( get_the_time( 'Y年m月d日' ) ) . '文章&quot;>' . $day . '日</a>';       return $out;   }   ?>   由于代码中有中文,记得将functions.php模版编码修改为:UTF-8 无BOM,否则中文会乱码。
  二,用下面代码:
<?php echo my_entry_published_link(); ?>  替换主题模版默认时间函数:
<?php the_time('Y年m月d日') ?>  包括:首页模版:index、文章页面模版:single、分类归档模版:archive、搜索结果模版:search等。
  替换完成后,可以分别点击日志发布日期的年,月,日,会打开相应的存档页面。
  原文地址:http://zmingcx.com/date-link-to-the-archive.html
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

 

 

快速回复 返回顶部 返回列表