Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_comment_excerpt [ WordPress Function ]

get_comment_excerpt ( $comment_ID = 0 )
Parameters:
  • (int) $comment_ID The ID of the comment for which to get the excerpt. Optional.
Uses:
Returns:
  • (string) The maybe truncated comment with 20 words or less
Defined at:



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.

Source


<?php
function get_comment_excerpt$comment_ID ) {
    
$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);
}
?>

Examples [ wp-snippets.com ]

Top Google Search Results

More ...

User discussions [ wordpress.org ]

0 User Note(s)

None yet. Be the first!

Add New ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics