php theexcerpt,wordpress函数get_comment_excerpt()用法示例

get_comment_excerpt( int|WP_Comment $comment_ID )

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.

参数

$comment_ID

(int|WP_Comment)

(Required)

WP_Comment or ID of the comment for which to get the excerpt. Default current comment.

返回值

(string) The maybe truncated comment with 20 words or less.

源代码

File: wp-includes/comment-template.php

function get_comment_excerpt( $comment_ID = 0 ) {

$comment = get_comment( $comment_ID );

$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );

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

/**

* Filters the amount 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', 20 );

$use_ellipsis = count( $words ) > $comment_excerpt_length;

if ( $use_ellipsis ) {

$words = array_slice( $words, 0, $comment_excerpt_length );

}

$excerpt = trim( join( ' ', $words ) );

if ( $use_ellipsis ) {

$excerpt .= '…';

}

/**

* 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 int $comment_ID The comment ID.

* @param WP_Comment $comment The comment object.

*/

return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );

}

更新日志

Version

描述

4.4.0

Added the ability for $comment_ID to also accept a WP_Comment object.

1.5.0

Introduced.

相关函数

Uses

wp-includes/comment-template.php:

comment_excerpt_length

wp-includes/plugin.php:

apply_filters()

wp-includes/comment-template.php:

get_comment_excerpt

wp-includes/comment.php:

get_comment()

Used By

wp-includes/comment-template.php:

comment_excerpt()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值