get_comment_excerpt

Definition:
function get_comment_excerpt( $comment_ID = 0 ) {}

Retrieve the excerpt of the current comment.
Will cut each word and only output the first 20 words with ‘…’ at the end. If the word count is less than 20, then no truncating is done and no ‘…’ will appear.

Parameters

  • int $comment_ID: The ID of the comment for which to get the excerpt. Optional.

Return values

returns:The maybe truncated comment with 20 words or less

Defined filters

  • get_comment_excerpt
    apply_filters('get_comment_excerpt', $excerpt)

Source code

function get_comment_excerpt( $comment_ID = 0 ) {

	$comment = get_comment( $comment_ID );

	$comment_text = strip_tags($comment->comment_content);

	$blah = explode(' ', $comment_text);

	if (count($blah) > 20) {

		$k = 20;

		$use_dotdotdot = 1;

	} else {

		$k = count($blah);

		$use_dotdotdot = 0;

	}

	$excerpt = '';

	for ($i=0; $i<$k; $i++) {

		$excerpt .= $blah[$i] . ' ';

	}

	$excerpt .= ($use_dotdotdot) ? '...' : '';

	return apply_filters('get_comment_excerpt', $excerpt);

}

1312

No comments yet... Be the first to leave a reply!

Leave a comment