Multiple excerpt lengths in wordpress
How about...
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt) >= $limit) {
array_pop($excerpt);
$excerpt = implode(" ", $excerpt) . '...';
} else {
$excerpt = implode(" ", $excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content) >= $limit) {
array_pop($content);
$content = implode(" ", $content) . '...';
} else {
$content = implode(" ", $content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
then in your template code you just use..
<?php echo excerpt(25); ?>
from: http://bavotasan.com/tutorials/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/
Multiple Wordpress excerpt lengths on single page
See this question and answer. There's a function that let's you specify how the length of the excerpt on an ad-hoc basis.
Wordpress: How to obtain different excerpt lengths depending on a parameter
uhm, answering me again, the solution was actually quite trivial. it's not possible, as far as i know, to pass a parameter to the function my_excerpt_length() (unless you want to modify the core code of wordpress), but it is possible to use a global variable. so, you can add something like this to your functions.php file:
function my_excerpt_length() {
global $myExcerptLength;
if ($myExcerptLength) {
return $myExcerptLength;
} else {
return 80; //default value
}
}
add_filter('excerpt_length', 'my_excerpt_length');
And then, before calling the excerpt within the loop, you specify a value for $myExcerptLength (don't forget to set it back to 0 if you want to have the default value for the rest of your posts):
<?php
$myExcerptLength=35;
echo get_the_excerpt();
$myExcerptLength=0;
?>
Related Topics
Forget Password Page, Creating a Generated Password to Email to the User
How to Create a Base64Encoded String from Image Resource
Permission Denied with Bash.Sh to Run Cron
Mysqli_Stmt::Execute() Expects Exactly 0 Parameters, 1 Given
How to Set Up Use Httponly Cookies in PHP
Detect Exif Orientation and Rotate Image Using Imagemagick
In MVC, Where Do You Draw the Line Between a Controller and Model
What Is the Syntax for Sorting an Eloquent Collection by Multiple Columns
Woocommerce: Check If Items Are Already in Cart
Alternative for MySQL_Num_Rows Using Pdo
Filling Gaps in Dates Returned from Database - Pure SQL Solution Possible
Fatal Error: Call to Undefined Method MySQLi_Result::Fetch_All()
Why PHP Iteration by Reference Returns a Duplicate Last Record
Codeigniter Sessions Not Working After Migration
Whats the Easiest Way to Determine If a User Is Online? (Php/Mysql)