WordPress 中文文档
Function Reference/the excerpt
出自WordPress Chinese 中文文档
wordpress.org.cn
目录 |
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 an automatic excerpt 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.
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 excerpt [...] marks.
the_excerpt() vs. the_content()
Sometimes it is more meaningful to use only the_content() function. the_content() will decide what to display according to whether ttlt;!--more--gt;/tt tag was used. The ttlt;!--more--gt;/tt tag splits post/page into two parts: only content before the tag should be displayed in listing. Remember that ttlt;!--more--gt;/tt is (of course) ignored when showing single post/page.
Usage
%%% ?php the_excerpt(); ? %%%
Parameters
This tag has no parameters.
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 is_archive() ) or category (tested by is_category() ) pages.
Both the examples below work for versions 1.5 and above.
?php if ( is_category() || is_archive() ) {
the_excerpt();
} else {
the_content();
} ?
Control Excerpt Length using Filters
By default, excerpt length is set to 55 words. To change excerpt length using excerpt_length filter, add the following code to ttfunctions.php/tt file in your theme:
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
Remove [...] string using Filters
Only in version 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 ttfunctions.php/tt file in your theme:
function new_excerpt_more($more) {
return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');
For versions 2.8.x and Older
function new_excerpt_more($excerpt) {
return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'new_excerpt_more');
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
function new_excerpt_more($more) {
global $post;
return 'a href='. get_permalink($post-ID) . . 'Read the Rest...' . '/a';
}
add_filter('excerpt_more', 'new_excerpt_more');
Notes
- Uses: get_the_excerpt.
- Uses: ttapply_filters()/tt for 'ttthe_excerpt/tt'.
Change Log
Since: 0.71
Source File
ttthe_excerpt()/tt is located in onlyincludecodewp-includes/post-template.php/code/onlyinclude
div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9
Template Description
Link to the source code on http://core.trac.wordpress.org/browser/.
Parameters
- filename
- (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.
Usage
Link to the stable version: pre已侦测回归模板: Template:Trac/pre
Link to trunk: pre已侦测回归模板: Template:Trac/pre
/div
wordpress.org.cn.
Related
body_class, next_image_link, next_post_link, next_posts_link, post_class, post_password_required, posts_nav_link, previous_image_link, previous_post_link, previous_posts_link, single_post_title, sticky_class, the_category, the_category_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, the_ID, the_meta, the_shortlink, the_tags, the_title, the_title_attribute, the_title_rss, wp_link_pages
includeonlydiv style=clear:both; background-color:#F7F7F7; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;See also index of Function Reference and index of Template Tags./div/includeonlynoinclude
Description
This Template is used by Codex:Template Messages.
Usage
pre 已侦测回归模板: Template:Message /pre
Result
已侦测回归模板: Template:Message
/noinclude

