Advertisement
Guest User

Untitled

a guest
Nov 17th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  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.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement