Advertisement
Guest User

Untitled

a guest
Jun 30th, 2011
4,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement