在WordPress首页和目录页显示摘要的方法
在WordPress系统中,默认的首页和目录页使用的书全文输出,这对于文章内容较长的博客来说很不方面,下面我介绍一个方法,可以简单的实现在WordPress首页和目录页显示摘要而非全文。
首先找到wp-content/themes下你使用的模板目录,查找目录中的文件,如果有home.php则修改home.php,没有的话就修改index.php,找到<?php the_content(); ?>这一行,将其修改为以下代码:
<?php if(is_category() || is_archive() || is_home() ) {
the_excerpt();
} else {
the_content('Read the rest of this entry »');
} ?>
<div><div><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> so far | <a href="<?php the_permalink() ?>">Read On »</a></div></div>
这时,你的WordPress首页和分类就显示为摘要信息而不是全文信息了。
这段代码可以在你的首页、存档页、目录页使用摘要输出,使用摘要输出后,整个WordPress的重复内容就少多了,很利于搜索引擎优化。
如用户不想修改代码,可以安装使用这个插件来实现首页摘要显示的功能。
以下是我的代码:
<!--摘要显示代码开始-->
<?php if(is_category() || is_archive() || is_home() ) {
the_excerpt();
} else {
the_content('Read the rest of this entry »');
} ?>
<div><div style="text-align:right"><?php comments_popup_link('暂无评论', '1 条评论', '% 条评论'); ?> <a href="<?php the_permalink() ?>">查看全文 »</a></div></div>
<!--摘要显示代码结束-->
<small ><?php the_time('F jS, Y') ?> by <?php the_author() ?> | <?php edit_post_link('Edit','',''); ?> </small>