As it says in the title, I’m looking for multiple excerpt lengths in WordPress.
I understand you can do this in functions.php:
function twentyten_excerpt_length( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
What I want to know is how you can have multiple of these each returning different numerical values so I can get short excerpts for sidebar loops, longer excerpts for featured loops, and the longest excerpt for the main article.
Something like using these in the templates:
<?php the_excerpt('length-short') ?>
<?php the_excerpt('length-medium') ?>
<?php the_excerpt('length-long') ?>
Cheers,
Dave
How about…
then in your template code you just use..
from: http://bavotasan.com/tutorials/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/
As for now, you can upgrade Marty’s reply:
You can also define custom ‘read more’ link this way:
This is what I came up with.
Add this to your
functions.php
It can be used like this.
This is the easiest way that I know of to add filters, that are callable from one function.
I was looking for this feature as well and most of the functions here are good and flexible.
For my own case I was looking for a solution that shows a different excerpt length only on specific pages. I’m using this:
Paste this code inside the themes functions.php file.
You can add to your functions.php file this function
Then call it in your template like this
The
wp_strip_all_tags
should prevent stray html tags from breaking the page.Documentation on functions
Going back to Marty’s reply:
I know it’s been well over a year since this reply got published, but it’s better late than never. For this to work with limits of over the WordPress default of 55, you need to replace this line:
with this line:
Otherwise, the function only works with an already trimmed-down piece of text.
I think we can now use
wp_trim_words
see here.Not sure what extra data escaping and sanitization needed to use this function, but it looks interesting.
Here an easy way to limit the content or the excerpt
change get_the_excerpt() by get_the_content() if you want the contents.
Regards