如何在WordPress显示文章摘要

使用the_excerpt() 和 the_content() 显示文章摘要的异同。

目录或归档页面经常需要输出文章的摘要,而不是输出正篇文章,输出摘要的有利于搜索引擎优化,而且也方便读者大体上了解文章内容。

输出文章摘要由两种方法:

1. the_excerpt()

打开wordpress数据库的wp-posts表我们可发现post_excerpt字段,the_excerpt()输出的内容就是此字段存储的信息。

the_excerpt()无参数,不支持内嵌标记,并且输出时会以…结尾。


在编辑文章时需在摘要部分填上相关摘要信息,如下图所示。

2. the_content()

如果文章里面使用<!--more-->,则会输出<!--more-->以前的内容,否则会输出正篇文章内容。

如果你想使用the_content(),在编辑文章的时候一定要在文章内容添加上<!--more-->。

使用the_excerpt()会填充post_execerpt字段,而the_content()不会额外增加数据库占用空间。

范例:在目录或归档页面输出摘要,其他位置输出全部内容。

<?php if ( is_category() || is_archive() ) {
the_excerpt();
} else {
the_content();
} ?>

1 Comment

  1. Pingback: WordPress 摘要输出原理分析 « 任鸟飞网页设计博客

发表评论

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

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!:

无觅相关文章插件,快速提升流量

任鸟飞网页设计博客 谜题推理 No.1 Web Design Gallery IndustryIdea LookForDesign AWebGallery Mobile Web Template iDesign Wallpaper Big Funny Picture iPhone Faves iPhone Mobi iPad Faves Android Faves BlackBerry Faves Best Design Magazine All Banner Templates Blog Earn Tips 是谁啊 只爱美人 家乡美 唯美爱 美人衣妆 AutoCAD 2D | Pro/E 3D江苏名企The HTML5 Templates