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 Jun 30th, 2011  |  syntax: None  |  size: 1.04 KB  |  views: 2,543  |  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. function my_excerpt($excerpt_length = 55, $id = false, $echo = true) {
  2.          
  3.     $text = '';
  4.    
  5.           if($id) {
  6.                 $the_post = & get_post( $my_id = $id );
  7.                 $text = ($the_post->post_excerpt) ? $the_post->post_excerpt : $the_post->post_content;
  8.           } else {
  9.                 global $post;
  10.                 $text = ($post->post_excerpt) ? $post->post_excerpt : get_the_content('');
  11.     }
  12.          
  13.                 $text = strip_shortcodes( $text );
  14.                 $text = apply_filters('the_content', $text);
  15.                 $text = str_replace(']]>', ']]>', $text);
  16.           $text = strip_tags($text);
  17.        
  18.                 $excerpt_more = ' ' . '[...]';
  19.                 $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
  20.                 if ( count($words) > $excerpt_length ) {
  21.                         array_pop($words);
  22.                         $text = implode(' ', $words);
  23.                         $text = $text . $excerpt_more;
  24.                 } else {
  25.                         $text = implode(' ', $words);
  26.                 }
  27.         if($echo)
  28.   echo apply_filters('the_content', $text);
  29.         else
  30.         return $text;
  31. }
  32.  
  33. function get_my_excerpt($excerpt_length = 55, $id = false, $echo = false) {
  34.  return my_excerpt($excerpt_length, $id, $echo);
  35. }