Advertisements

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

Advertisements

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: