当博文写的比较长,特别是每篇都比较长的时候,要查看其中的一篇还是比较费劲的,因此需要让文章仅输出一部分,这样用户浏览的时候会很方便,也不会错过好的文章:
网上很多文章都要求改动主题目录下的index.php,但是twentyten中的index.php中根本没有the_content()语句:
1: <div id="container">
2: <div id="content" role="main">
3:
4: <?php
5: /* Run the loop to output the posts.
6: * If you want to overload this in a child theme then include a file
7: * called loop-index.php and that will be used instead.
8: */
9: get_template_part( 'loop', 'index' );
10: ?>
11: </div><!-- #content -->
12: </div><!-- #container -->
需要修改的内容隐藏在loop.php中,我们需要将
1: <div class="entry-content">
2: <?php if ( post_password_required() ) : ?>
3: <?php the_content(); ?>
4: <?php else : ?>
5: ...
6: </div>
修改为:
1: <div class="entry-content">
2: <?php if ( post_password_required() ) : ?>
3: <?php
4: if (is_single() or is_page()) {
5: the_content();
6: } else {
7: the_excerpt();
8: } ?>
9: <?php else : ?>
10: ...
11: </div>
保存更新即可。