wordpress显示文章摘要的方法
wordpress的很多主题,在主页中都无法显示文章摘要,虽然有很多插件可以完成这一功能,但没有下面这个方法使用方便。其实问题就是出现在
1 | <?php the_content(); ?> |
这行代码中。根据自己所用的主题,找到home.php,如果没有就找到index.php,找到
1 | <?php the_content(); ?> |
这句代码,将其修改为:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php if(is_category() || is_archive() || is_home() ) { the_excerpt(); } else { the_content('Read the rest of this entry »'); } ?> <div class="details"> <div class="inside"> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> so far | <a href="<?php the_permalink() ?>">Read On »</a></div> </div> |
如果自己的主题没有category或者archive页面,可根据实际情况修改。
这样使各个页面都以文章摘要的形式输出,不仅使自己页面看上去整洁,也有利于搜索引擎人优化。