有时候博客主页上只显示文章摘要是很有好处的, 比如文章过长的时候用户就不方便定位文章. 只在首页, 搜索页, 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/
GD Star Rating
loading...
本文一共 298 个汉字, 你数一下对不对.loading...
上一篇: 说说生孩子的那些事
下一篇: 投诉 npower 电气公司
扫描二维码,分享本文到微信朋友圈
好家伙,这方法不错,不用手工再去设置.
我也跟上你的节奏了.哈哈.
呵呵, 互相学习, 互相进步.
你感觉你这设置会提高PV浏览量,因为要多点击几次,同时也提高了ADS显示次数,并且首页的广告点击率也会提高许多——广告占的面积会更多——不过看首页的都是老读者,广告看不到.
观察一段时间看看.
动作真快…
翻了那么多文章,还是你这个最靠谱!本来想查查土木坛子是怎么实现的摘要,找到你这了哈哈~
嗯 JUSTYY出品 必属精品 🙂