落絮飞雁

顺流而下,把梦做完

让WordPress首页只显示摘要

WordPress的功能很强大,可以根据个人需求来修改网站。

在Wordpress 3.5.1的中提供了默认的主题Twenty Twelve,很不错,但是首页显示的是全文信息,这不仅使得页面太长,也使得加载速度变的很慢,只有在搜索的时候才会显示摘要,那么怎么去让首页显示文章的摘要呢?
到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>&rarr;</span>', 'twentyeleven' ) );
?>

将它修改为

<?php if(!is_single()) {
the_excerpt();
} else {
the_content(__('(more…)'));
} ?>

保存,现在去看看你的首页,是不是只显示摘要了?


 

转载自:http://www.iteblog.com/archives/21


原文标题:让WordPress首页只显示摘要|落絮飞雁的个人网站
原文链接:https://www.luoxufeiyan.com/2014/12/21/%e8%ae%a9wordpress%e9%a6%96%e9%a1%b5%e5%8f%aa%e6%98%be%e7%a4%ba%e6%91%98%e8%a6%81/
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。