大多数情况下WordPress博客为了更多地展示精彩文章,会在侧边小工具中添加一个基于日期的文章归档列表,不过这样不仅占用了侧边大块的空间,而且也不是很美观。下面的方法可以在不占用任何额外的空间的前提下,方便读者按年,月,日阅览日志文章,增加流量。
一般的WordPress主题都会在显著的位置注明日志的发布或者修改日期,并没有什么实用价值,我们的目的就是将年,月,日连接到相应的存档页面。
一,将下面的代码添加到主题functions.php模版的最后:
- <?php
- add_shortcode( \’entry-link-published\’, \’my_entry_published_link\’ );
- my_entry_published_link() {
- = get_the_time( \’Y\’ );
- = get_the_time( \’m\’ );
- = get_the_time( \’d\’ );
- = ;
- .= \'<a href= title=>\’ . . \’年</a>\’;
- .= \'<a href= title=>\’ . get_the_time( \’m月\’ ) . \'</a>\’;
- .= \'<a href= title=>\’ . . \’日</a>\’;
- ;
- }
- ?>
由于代码中有中文,记得将functions.php模版编码修改为:UTF-8 无BOM,否则中文会乱码。
二,用下面代码:
- <?php my_entry_published_link(); ?>
替换主题模版默认时间函数:
- <?php the_time(\’Y年m月d日\’) ?>
包括:首页模版:index、文章页面模版:single、分类归档模版:archive、搜索结果模版:search等。
替换完成后,可以分别点击日志发布日期的年,月,日,会打开相应的存档页面。
具体效果可以点击查看本博日志标题下的日期。
原文:Linking post published dates to their archives
暂无评论内容