Get Excerpt by ID

<?php

function hyp_excerpt_by_id($post,$length = 10,$tags_to_keep = '',$extra = '&hellip;'){
if(is_int($post)) $post = get_post($post);
elseif(!is_object($post)) return false;
if(has_excerpt($post->ID)) return $post->post_excerpt;
else $the_excerpt = $post->post_content;
$the_excerpt = strip_shortcodes(strip_tags($the_excerpt), $tags_to_keep);
$the_excerpt = preg_split('/b/', $the_excerpt, $length * 2+1);
$excerpt_waste = array_pop($the_excerpt);
$the_excerpt = implode($the_excerpt);
$the_excerpt .= $extra;
return $the_excerpt;
}

?>

0 Comments

You must be logged in to post a comment.