WordPress 中文文档

Template Tags/the excerpt

出自WordPress Chinese 中文文档

跳转到: 导航, 搜索

目录

Description

Displays the excerpt of the current post with [...] at the end, which is not a read more link. If you do not provide an explicit excerpt to a post (in the post editor's optional excerpt field), it will display a teaser which refers to the first 55 words of the post's content. Also in the latter case, HTML tags and graphics are stripped from the excerpt's content. This tag must be within The Loop.

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 excerpt [...] marks.

Usage

%%% ?php the_excerpt(); ? %%%

Examples

Default Usage

Displays the post excerpt. Used on non-single/non-permalink posts as a replacement for the_content() to force excerpts to show within the Loop.

?php the_excerpt(); ?

Use with Conditional Tags

Replaces the_content() tag with the_excerpt() when on archive (tested by ttis_archive()/tt) or category (ttis_category()/tt) pages.

Both the examples below work for versions 1.5 and above.

%%% ?php if(is_category() || is_archive()) {

	the_excerpt();
} else {
	the_content();
} ? %%%

For versions of WordPress prior to 1.5, only the following will work :

%%% ?php if($cat || $m) {

	the_excerpt();
} else {
	the_content();
} ? %%%

Parameters

This tag has no parameters.

Comparison of the_excerpt() vs. the_content()

Sometimes is more meaningful to use only the_content() function. the_content() will decide what to display according to whether %%%!--more--%%% tag was used.

%%%!--more--%%% tag splits post/page into two parts: only content before tag should be displayed in listing.

Remember that %%%!--more--%%% is (of course) ignored when showing only post/page (singles).

Related

the_ID, the_title, the_title_attribute, single_post_title, the_title_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, previous_post_link, next_post_link, posts_nav_link, the_meta,

div style=background: #f7f7f7; border: 1px solid #000; padding: 10px; Go to Template Tag index/div

wordpress