Loading
0

获取评论内容WordPress函数comment_text

WordPress也提供了一系列的评论函数来增强互动,提升网站活性,comment_text函数就是用来获取评论内容的函数,理解它我们才能更灵活的实现我需要的互动逻辑。下面我们一起来看看获取评论内容WordPress函数comment_text。

获取评论内容WordPress函数comment_text

在评论循环中显示游标所在数据的评论内容。

函数原型

comment_text函数位于wp-includes/comment-template.php文件中,下面是它的源码:

function comment_text( $comment_ID = 0, $args = array() ) {

$comment = get_comment( $comment_ID );

$comment_text = get_comment_text( $comment, $args );

/**

* Filters the text of a comment to be displayed.

*

* @since 1.2.0

*

* @see Walker_Comment::comment()

*

* @param string $comment_text Text of the current comment.

* @param WP_Comment|null $comment The comment object.

* @param array $args An array of arguments.

*/

echo apply_filters( 'comment_text', $comment_text, $comment, $args );

}

前面已经说了很多次这种函数的构造了,比如the_title与get_the_title,这里我就不多说了,不明白的自己去看前面的文章。

参数说明

comment_text( int|WP_Comment $comment_ID, array $args = array() )

$comment_ID

(int|WP_Comment) (必须) 你需要的评论id,默认为当前循环游标所在评论id。

$args

(数组) (可选) 一个数组参数

默认值: 空数组

简单使用

<?php comment_text(); ?>

使用comment_text获取评论内容,你可能需要学习WordPress获取评论数据函数wp_list_comments详解。