让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

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注