以下は、投稿オブジェクトまたは投稿IDをパラメーターとして受け取る「trim_excerpt」の例です。
明らかにコアにあるものに基づいています。なぜこれ(およびget_the_author())に同等の非ループがないのかわかりません。
/**
* Generates an excerpt from the content, if needed.
*
* @param int|object $post_or_id can be the post ID, or the actual $post object itself
* @param string $excerpt_more the text that is applied to the end of the excerpt if we algorithically snip it
* @return string the snipped excerpt or the manual excerpt if it exists
*/
function zg_trim_excerpt($post_or_id, $excerpt_more = ' [...]') {
if ( is_object( $post_or_id ) ) $postObj = $post_or_id;
else $postObj = get_post($post_or_id);
$raw_excerpt = $text = $postObj->post_excerpt;
if ( '' == $text ) {
$text = $postObj->post_content;
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
// don't automatically assume we will be using the global "read more" link provided by the theme
// $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $excerpt_more;
} else {
$text = implode(' ', $words);
}
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
$myvar = apply_filters( 'the_excerpt', $myvar );