Advertisement
eventsmanager

Excerpt Length

Feb 25th, 2013
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. /**
  2. This snippet will override placeholder #_EXCERPT which will
  3. limit the event details to 120 characters with read more link.
  4. */
  5. add_filter('em_event_output_placeholder','my_em_styles_placeholders',1,3);
  6. function my_em_styles_placeholders($replace, $EM_Event, $result){
  7.     switch( $result ){
  8.         case '#_EXCERPT':
  9.  
  10.         $maxchars = 120;
  11.         $text = $replace;
  12.  
  13.         if(strlen($text) > $maxchars) {
  14.                 $text = substr($text, 0, $maxchars);
  15.                 $position = strrpos($text, " ");
  16.                 if($position > 0) {
  17.                     $text = substr($text, 0, $position);
  18.                 }
  19.                 return $text.'...<a href="'.$EM_Event->output('#_EVENTURL').'" class="eventreadmore">Read More...</a>';
  20.         }          
  21.  
  22.         break;
  23.     }
  24.     return $replace;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement