get_comment_excerpt

函数
get_comment_excerpt ( $comment_ID = 0 )
参数
  • (int|WP_Comment) $comment_ID WP_Comment or ID of the comment for which to get the excerpt. Default current comment.
    Required:
返回值
  • (string) The possibly truncated comment excerpt.
定义位置
相关方法
comment_excerptget_comment_textget_comment_metaget_comment_countget_the_excerpt
引入
1.5.0
弃用
-

get_comment_excerpt – 这个函数返回一个评论的简短摘录。默认情况下,它返回评论文本的前20个字,但你可以用过滤器定制字数和”更多”文本。它把评论的ID作为一个参数。

检索给定评论的摘录。

最多返回20个字,必要时附加省略号。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_comment_excerpt( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( ! post_password_required( $comment->comment_post_ID ) ) {
$comment_text = strip_tags( str_replace( array( "n", "r" ), ' ', $comment->comment_content ) );
} else {
$comment_text = __( 'Password protected' );
}
/* translators: Maximum number of words used in a comment excerpt. */
$comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );
/**
* Filters the maximum number of words used in the comment excerpt.
*
* @since 4.4.0
*
* @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
*/
$comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );
$excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' );
/**
* Filters the retrieved comment excerpt.
*
* @since 1.5.0
* @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
*
* @param string $excerpt The comment excerpt text.
* @param string $comment_ID The comment ID as a numeric string.
* @param WP_Comment $comment The comment object.
*/
return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
}
function get_comment_excerpt( $comment_ID = 0 ) { $comment = get_comment( $comment_ID ); if ( ! post_password_required( $comment->comment_post_ID ) ) { $comment_text = strip_tags( str_replace( array( "n", "r" ), ' ', $comment->comment_content ) ); } else { $comment_text = __( 'Password protected' ); } /* translators: Maximum number of words used in a comment excerpt. */ $comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' ); /** * Filters the maximum number of words used in the comment excerpt. * * @since 4.4.0 * * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. */ $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); /** * Filters the retrieved comment excerpt. * * @since 1.5.0 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. * * @param string $excerpt The comment excerpt text. * @param string $comment_ID The comment ID as a numeric string. * @param WP_Comment $comment The comment object. */ return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment ); }
function get_comment_excerpt( $comment_ID = 0 ) {
	$comment = get_comment( $comment_ID );

	if ( ! post_password_required( $comment->comment_post_ID ) ) {
		$comment_text = strip_tags( str_replace( array( "n", "r" ), ' ', $comment->comment_content ) );
	} else {
		$comment_text = __( 'Password protected' );
	}

	/* translators: Maximum number of words used in a comment excerpt. */
	$comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );

	/**
	 * Filters the maximum number of words used in the comment excerpt.
	 *
	 * @since 4.4.0
	 *
	 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
	 */
	$comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );

	$excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' );

	/**
	 * Filters the retrieved comment excerpt.
	 *
	 * @since 1.5.0
	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
	 *
	 * @param string     $excerpt    The comment excerpt text.
	 * @param string     $comment_ID The comment ID as a numeric string.
	 * @param WP_Comment $comment    The comment object.
	 */
	return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
}

常见问题

FAQs
查看更多 >