Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 17th, 2011  |  syntax: PHP  |  size: 1.03 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Excerpt {
  2.  
  3.   // Default length (by WordPress)
  4.   public static $length = 55;
  5.  
  6.   // So you can call: my_excerpt('short');
  7.   public static $types = array(
  8.       'short' => 25,
  9.       'regular' => 55,
  10.       'long' => 100
  11.     );
  12.  
  13.   /**
  14.    * Sets the length for the excerpt,
  15.    * then it adds the WP filter
  16.    * And automatically calls the_excerpt();
  17.    *
  18.    * @param string $new_length
  19.    * @return void
  20.    * @author Baylor Rae'
  21.    */
  22.   public static function length($new_length = 55) {
  23.     Excerpt::$length = $new_length;
  24.  
  25.     add_filter('excerpt_length', 'Excerpt::new_length');
  26.  
  27.     Excerpt::output();
  28.   }
  29.  
  30.   // Tells WP the new length
  31.   public static function new_length() {
  32.     if( isset(Excerpt::$types[Excerpt::$length]) )
  33.       return Excerpt::$types[Excerpt::$length];
  34.     else
  35.       return Excerpt::$length;
  36.   }
  37.  
  38.   // Echoes out the excerpt
  39.   public static function output() {
  40.     the_excerpt();
  41.   }
  42.  
  43. }
  44.  
  45. // An alias to the class
  46. function my_excerpt($length = 55) {
  47.   Excerpt::length($length);
  48. }
  49.