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()

php theexcerpt,wordpress函数get_comment_excerpt()用法示例相关推荐

  1. php中mimes函数,wordpress函数check_upload_mimes()用法示例

    check_upload_mimes( array $mimes ) Check an array of MIME types against a whitelist. 描述 WordPress sh ...

  2. php getfooter,wordpress函数get_footer()用法示例

    get_footer( string $name = null ) Load footer template. 描述 Includes the footer template for a theme ...

  3. add php support,wordpress函数add_post_type_support()用法示例

    add_post_type_support( string $post_type, string|array $feature ) Register support of certain featur ...

  4. PHP Calendar 函数,wordpress函数get_calendar()用法示例

    get_calendar( bool $initial = true, bool $echo = true ) Display calendar with days that have posts a ...

  5. escilpe mysql,wordpress函数esc_sql()用法示例

    esc_sql( string|array $data ) Escapes data for use in a MySQL query. 描述 Usually you should prepare q ...

  6. php geteditor,wordpress函数get_editor_stylesheets()用法示例

    get_editor_stylesheets() Retrieve any registered editor stylesheets 描述 返回值 (array) If registered, a ...

  7. php函数clean(),wordpress函数clean_url()用法示例

    Warning: This function has been deprecated. Use esc_url() instead. clean_url( string $url, array $pr ...

  8. ?php get_sidebar(); ?,wordpress函数get_sidebar()用法示例

    get_sidebar( string $name = null ) Load sidebar template. 描述 Includes the sidebar template for a the ...

  9. html class函数,wordpress函数sanitize_html_class()用法示例

    sanitize_html_class( string $class, string $fallback = '' ) Sanitizes an HTML classname to ensure it ...

  10. php theexcerpt,wordpress的excerpt()函数的用法示例

    本篇文章给大家带来的内容是关于wordpress的excerpt()函数的用法示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 问题:在wordpres中的single页面,本身引 ...

最新文章

  1. java jackson json_java – 使用Jackson从JSON获取单个字段
  2. 1-STM32+W5500+GPRS物联网开发基础篇-工控板简介
  3. 删除360浏览器新标签页内的热词导航
  4. Ubuntu14.04 x64系统设置Qt5.8桌面快捷方式
  5. python中numpy矩阵运算操作大全(非常全)!
  6. OSChina 周二乱弹 —— 加班的代码不要枉费了我的童子功
  7. AD显示隐藏管脚——谈mos管封装的一个坑处
  8. graphpad做饼图_超省钱的早餐攻略!这些边角料可别扔,多做一步变大餐!
  9. Java集合框架学习总结
  10. 应聘游戏策划是否该将完整策划案给面试官看
  11. 火狐网页访问https提示安全连接失败
  12. 利用github进行账号授权登录
  13. c++ value categories
  14. i5功耗最低的cpu_CPU真的很费电? 三种环境下处理器功耗实测
  15. bilinear interpolation是什么
  16. 来淄博旅游 C 2055
  17. [记录] JavaScript 中的正则表达式
  18. 2019, XII Samara Regional Intercollegiate Programming Contest 全部题解
  19. 15篇大数据精品文章大合集
  20. 三国志战略版:Daniel_赤壁前瞻3_地图战略及配将思路

热门文章

  1. D3.js中文API
  2. QCustomPlot系列(2)-绘制两条曲线+自动全显+鼠标拖放+rescaleAxes()函数简介
  3. java访问邮箱 apache,关于apache common-mail发邮件,部分邮箱无法接收有关问题
  4. 华为 荣耀 6x android哪个版本,华为荣耀畅玩6X官方rom刷机包_华为荣耀6X原版系统包_升级包...
  5. 多种参数的BCH、RS码和(2,1,6)卷积码编码的MATLAB仿真实现
  6. VMware虚拟机中如何配置ip地址网关和dns
  7. 带你一文了解hourglass
  8. python数据挖掘课后题答案_中国大学MOOC《数据挖掘与python实践》章节答案
  9. 小班安全使用计算机教案,安全用电器幼儿园小班安全教案
  10. 什么是PR、什么是BD?