Codex tools: Log in / create account
Contents |
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.
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.
Sometimes it is more meaningful to use only the_content() function. the_content() will decide what to display according to whether <!--more--> tag was used. The <!--more--> tag splits post/page into two parts: only content before the tag should be displayed in listing. Remember that <!--more--> is (of course) ignored when showing single post/page.
<?php the_excerpt(); ?>
This tag has no parameters.
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(); ?>
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();
} ?>
For versions of WordPress prior to 1.5, only the following will work :
<?php if ( $cat || $m ) {
the_excerpt();
} else {
the_content();
} ?>
By default, excerpt length is set to 55 words. To change excerpt length using excerpt_length filter, add the following code to functions.php file in your theme:
function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');
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:
function new_excerpt_more($more) {
return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');
function new_excerpt_more($excerpt) {
return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'new_excerpt_more');
Place this in a theme's functions.php to make the "read more" link to the post
function new_excerpt_more($more) {
return '<a href="'. get_permalink($post->ID) . '">' . ' read on ..' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
Since: 0.71
the_excerpt() is located in wp-includes/post-template.php.
the_ID, the_title, the_title_attribute, single_post_title, the_title_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, wp_link_pages, next_post_link, next_posts_link, previous_post_link, previous_posts_link, posts_nav_link, sticky_class, the_meta