Displays the excerpt of the current post after applying several filters to it including auto-p formatting which turns double line-breaks into HTML paragraphs. It uses get_the_excerpt() to first generate a trimmed-down version of the full post content should there not be an explicit excerpt for the post.

The trimmed-down version contains a 'more' tag at the end which by default is the […] or "hellip" symbol. A user-supplied excerpt is NOT by default given such a symbol. To add it, you must either modify the raw $post->post_excerpt manually in your template before calling the_excerpt(), add a filter for 'get_the_excerpt' with a priority lower than 10, or add a filter for 'wp_trim_excerpt' (comparing the first and second parameter, because a user-supplied excerpt does not get altered in any way by this function).

See get_the_excerpt() for more details.

An auto-generated excerpt will also have all shortcodes and tags removed. It is trimmed down to a word-boundary and the default length is 55 words. For languages in which words are (or can be) described with single characters (ie. East-Asian languages) the word-boundary is actually the character.

Note: If the current post is an attachment, such as in the attachment.php and image.php template loops, then the attachment caption is displayed. Captions do not include the "[...]" text.

the_excerpt() 描述


 <?php the_excerpt(); ?> 

This template tag must be used within The Loop.

the_excerpt() 用法


This tag has no parameters.

the_excerpt() 参数


Default Usage

Displays the post excerpt. Used in templates that provide a form of index, ie. for home, category, tag, archive pages. Not used for single post views. Not meaningful for static pages.

Used as a replacement for the_content() to force excerpts to show within The Loop.

Use with Conditional Tags

Replaces the_content() tag with the_excerpt() when on archive or category pages.

Both the examples below work for versions 1.5 and above.

This example implies that there is only one template file being used for both categories and archives, e.g. simply archive.php. But also that the template shows even other things, so this could simply be index.php.

Control Excerpt Length using Filters

By default, excerpt length is set to 55 words. To change excerpt length to 20 words using excerpt_length filter, add the following code to functions.php file in your theme:

Remove […] string using Filters

In WordPress version 2.9, a new filter was added to make changing the [...] string in the excerpt. Do not use both of these methods in the same WordPress installation. Use the one appropriate for your WordPress version.

For versions 2.9 and higher of WordPress

By default, excerpt more string at the end is set to '[…]'. To change excerpt more string using excerpt_more filter, add the following code to functions.php file in your theme:

For versions 2.8.x and Older

Make the "read more" link to the post

Place this in a theme's functions.php to make the "read more" link to the post

Note: This link will not appear in a new line. You'll need to use CSS on the read-more class.

the_excerpt() 示例


the_excerpt() 注意


添加于 版本: 0.71

the_excerpt() 历史


the_excerpt() 函数的代码位于 wp-includes/post-template.php.

the_excerpt() 源文件