最近给实验室做网页,是基于WP开发的。 研究了两个多星期,算是有些收获,懂得了很多东西。
转入正题,关于WP的摘要显示问题。网络上有很多关于这样的文章,大都是天下文章一大抄,清一色的全是更改index.php中的<?php the_content();?> 为 <?php the_excerpt();?> ,但是WP的the_excerpt();函数对中文的支持不是很好,导致了调用此函数之后仍然是显示全文的现象。
解决方法:
1. 首先安装插件wp-utf8-excerpt,这个插件出自
http://myfairland.net/wp-utf8-excerpt/ 这篇文章。
2. 在WP的插件的选项栏中启用此插件。
3.修改index.php文件
将<?php the_content();?>
更改为:
<?php
if (is_single() or is_page()) {
the_content();
} else {
the_excerpt();
}
?>
if (is_single() or is_page()) {
the_content();
} else {
the_excerpt();
}
?>
这样修改之后就可以实现首页文章的摘要显示了。
上述代码首先判断新打开的页面是否为单篇具体文章,如果是,则the_content()显示全文,如果不是,则利用the_excerpt()显示摘要。
也可以从本文附件中下载~~
转载于:https://blog.51cto.com/greyshine/220282