tags:

views:

118

answers:

1

Example I want use 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()

  1. Option 1 = the_excerpt() limit to 100 chars
  2. Option 2 = the_excerpt() limit to 200 chars
  3. Option 3 = the_excerpt() limit to 300 chars
+1  A: 

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.

KennyCason
I tried.. but if we set limit example to 100 chars, the value will return to normal and being 20 only.. at the moment I just change `the_excerpt` to be `the_content_rss('', FALSE, '', 100);` and it's worked
kampit
according to the codex, the_content_rss the function has been deprecated.
kampit
When I get home tonight I will look through it and see if I can whip up something nice.
KennyCason