Example I want 开发者_StackOverflowuse the_excerpt
in two locations. On functions.php
I add
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
Question.
How to make another function to accept another the_excerpt
will be 200 characters?
Or another solutions.
How to make something like this.. Dynamic the_excerpt()
- Option 1 =
the_excerpt()
limit to 100 chars - Option 2 =
the_excerpt()
limit to 200 chars - Option 3 =
the_excerpt()
limit to 300 chars
Have you read through the WordPress documentation for the_excerpt()
http://codex.wordpress.org/Function_Reference/the_excerpt
It appears that you can only override the the excerpt_length() with new_excerpt_length() via filters as you mentioned.
So perhaps you can modify existing the_excerpt function to take a parameter $length, where the default value = null. If you are familiar with PHP you know that you don't have to pass any parameters to the_excerpt()
, in which case $length will default to null and function as if $length was never passed to it, which means all current usages of the_excerpt() will continue working as normal. and if you want print your excerpt at a different length then call the_excerpt(someOtherLength);
It will look something like this.
function the_excerpt($length=null) {
if($length != null) {
// ignore default excerpt length with $length
// print the excerpt to $length
} else {
// prints the excerpt to standard length specified by excerpt_length()
}
}
Let me know if you have any problems.
精彩评论