有时候博客主页上只显示文章摘要是很有好处的, 比如文章过长的时候用户就不方便定位文章. 只在首页, 搜索页, Tag, 目录类别, 还有存档页显示文章标题, 还有一两句话摘要 则会让页面显得简洁许多.
其实你只需要编辑模板页面 content.php (推荐子主题),然后找到下面这行代码:
1 | <?php if ( is_search() ) : // Only display Excerpts for Search ?> |
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
把它改成:
1 | <?php if ( is_search() || is_home() || is_tag() || is_category() || is_archive() ) : // Only display Excerpts for Search ?> |
<?php if ( is_search() || is_home() || is_tag() || is_category() || is_archive() ) : // Only display Excerpts for Search ?>
函数 is_archive() 检查当前页面是否是 目录 (is_category), 标签 (is_tag), 作者 或者是日期存档页面. 在下一行, 你可以看到用了 the_excerpt() 函数来显示文章摘要. 显示文章全文则需要用函数 the_content().
如果想在摘要后面加入全文链接, 则可以编辑模板文件 functions.php (最好在子主题里编辑), 在文件最后面加入以下内容.
1 2 3 4 5 6 7 8 9 10 11 | // Remove the .. from excerpt and change the text function change_excerpt_more() { function new_excerpt_more($more) { // Use .read-more to style the link return '<span class="continue-reading"> <a href="' . get_permalink() . '">继续阅读 »</a></span>'; } add_filter('excerpt_more', 'new_excerpt_more'); } add_action('after_setup_theme', 'change_excerpt_more'); |
// Remove the .. from excerpt and change the text function change_excerpt_more() { function new_excerpt_more($more) { // Use .read-more to style the link return '<span class="continue-reading"> <a href="' . get_permalink() . '">继续阅读 »</a></span>'; } add_filter('excerpt_more', 'new_excerpt_more'); } add_action('after_setup_theme', 'change_excerpt_more');
这些修改并不影响 RSS Feed 里文章输出的格式. 如果想在FEED里显示文章摘要,则需要到设置-阅读, 然后更改相应的选项: “For each article in a feed, show” 改成 “总结 Summary” 而不是 “全文 Full Text”. 然而,这个设置会影响其它页面, 比如主页面和搜索页面.
英文同步: https://helloacm.com/showing-excerpts-in-wordpress-home-search-tag-and-archive-pages/
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK