免费屋|Xls经验|免费小屋|路豪论坛|免费资源网|免费软件园|免费图片网|免费电影下载|免费音乐网|在线网游园|视频短片|免费在线影院|免费动漫网|免费影院|GAE经验

关于WordPress只显示摘要的方法



By admin ~ December 3rd, 2008. Filed under: WordPress经验.

一、通过Yskin’s wp-CJK-excerpt 1.3 插件实现:
Yskin’s wp-CJK-excerpt 1.3 为WordPress用户提供更好的摘要算法,以解决WordPress默认摘要算法只考虑西方语言的不足。使用这个插件可以很好地显示文章摘要:
wp-CJK-excerpt 1.3 下载地址
要修改模板文件index.php页面中的下面这行代码:
<?php the_content(‘Read the rest of this entry ?’); /*引号中也有可能是其它内容*/ ?>
修改这一行为:

<?php the_excerpt(); ?>
对于没有single.php页面的,还需要自建一个single.php文件,添加如下代码:
<?php if (is_single()) { ?>
<?php the_content(’Read the rest of this entry ?’); ?>
<?php } else { ?>
<?php the_excerpt(); ?>
<?php } ?>
这样就可以了。

此外,对于K2主题,是修改theloop.php文件,找到

<?php the_content(sprintf(__(’Continue reading ’%s”, ‘k2_domain’), the_title(”, ”, false)));?>
然后改成

<?php if (is_single()) { ?>
<?php the_content(sprintf(__(’Continue reading ’%s”, ‘k2_domain’), the_title(”, ”, false)));?>
<?php } else { ?>
<?php the_excerpt(); ?>
<?php } ?>
就可以了。
注意:如果要在Categories和Archives也仅显示摘要,则在Categories和Archives相应模板里也要改一下

二、最简单的无插件法:
1、使用more标签 (缺点:每次都要加一下这个东西,不灵活只能一刀切。优点:方法比较正规不需要改动模版)

在你需要截断的地方(就是你的编辑框)加 <!–more–> 代码.

2、使用the_excerpt标签 (缺点:需要改动模版,而且显示的是纯文本。优点:一劳永逸直接把想要的部分来做摘要)

使用方法,注意是编辑你的模版中(wp-contant/themes/你的模版/index.php) 文件)。

找到

<?php the_content(__(’(more…)’)); ?>

<?php the_content(); ?>
修改为:

<?php if(!is_single()) {
the_excerpt();
} else {
the_content(__(‘(more…)’));//或者
} ?>
现在你的wordpress,除非打开单个post,其他情况下都是显示摘要。

注意:这种方法有可能导致部分plugin失效,虽然我的暂时未出现状况;文中链接不会在摘要中显示。当然你可以使用[code]模式选取摘要的内容复制到摘要里面去,这样摘要也可以显示链接而且排版形式也同文章一致了。

三、现在告诉您我自己修改成功的方法:
在模板(index.php)文件中找到:
<?php the_content('Continue reading »'); /*括号或引号中也有可能是其它内容*/ ?>
将其修改为:
<?php if(!is_single()) { ?>
<?php the_excerpt(); ?>
<?php } else { ?>
<?php the_content('Continue reading »'); /*此处内容应与前面找到的一致!*/ ?>
<?php } ?>
Update File即OK!

四、肯定还有更多,点击此链接或这里可以查看更多!

Tags: , , ,

Leave a Comment

You must be logged in to post a comment.