内容纲要
wordpress首页显示全文不但拖慢了加载速度,还覆盖了好的文章,浪费页面空间。之前为了这个解决问题查了不少资料。终于在过往记忆该篇文章(此处致谢!)的帮助下完成了这一操作,但部分内容因为主题不同略有区别。
原教程使用的 主题Twenty Twelve ,我是用的Twenty Fifteen。
下面贴出原教程和对应的改动。
原教程:
到wordpress后台,依次选择 外观-->编辑-->选择右边的index.php文件,在里面可以看到语句
<?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content' , get_post_format() ); ?> <?php endwhile ; ?> |
可以看出,index.php是嵌套一个 content.php 的文件用于专门显示文章的内容,这就是为什么在首页老是显示文章全文。那么,打开content.php文件找到
<?php the_content( __( 'Continue reading <span>→</span>' , 'twentyeleven' ) ); ?> |
将它修改为
<?php if(!is_single()) {the_excerpt();} else {the_content(__('(more…)'));} ?> |
改动:
可以看到原教程分成三步
第一步经验证完全符合,
第二步第三步:
找到line32--line37
the_content( sprintf( __( 'Continue reading %s', 'twentyfifteen' ), the_title( '<span class="screen-reader-text">', '</span>', false ) ) ); |
替换为:
if(!is_single()) {the_excerpt();} else {the_content(__('(more…)'));} |
OK,over。其他主题照情况来改就行
友情提示,修改前最好做个备份避免网站崩溃。

留言