separate_comments

函数
separate_comments ( $comments )
参数
  • (WP_Comment[]) $comments Array of comments
    Required:
返回值
  • (WP_Comment[]) Array of comments keyed by comment_type.
定义位置
相关方法
get_commentshave_commentsthe_commentwp_update_commentwp_insert_comment
引入
2.7.0
弃用
-

separate_comments: 这是一个WordPress的函数,它根据评论的类型将其分离成不同的数组。它通常被用来分别显示评论和回帖,并定制每种类型的输出: 这个函数有一个参数,就是要分离的评论数组。

将一个评论数组分离成一个以comment_type为关键字的数组。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function separate_comments( &$comments ) {
$comments_by_type = array(
'comment' => array(),
'trackback' => array(),
'pingback' => array(),
'pings' => array(),
);
$count = count( $comments );
for ( $i = 0; $i < $count; $i++ ) {
$type = $comments[ $i ]->comment_type;
if ( empty( $type ) ) {
$type = 'comment';
}
$comments_by_type[ $type ][] = &$comments[ $i ];
if ( 'trackback' === $type || 'pingback' === $type ) {
$comments_by_type['pings'][] = &$comments[ $i ];
}
}
return $comments_by_type;
}
function separate_comments( &$comments ) { $comments_by_type = array( 'comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array(), ); $count = count( $comments ); for ( $i = 0; $i < $count; $i++ ) { $type = $comments[ $i ]->comment_type; if ( empty( $type ) ) { $type = 'comment'; } $comments_by_type[ $type ][] = &$comments[ $i ]; if ( 'trackback' === $type || 'pingback' === $type ) { $comments_by_type['pings'][] = &$comments[ $i ]; } } return $comments_by_type; }
function separate_comments( &$comments ) {
	$comments_by_type = array(
		'comment'   => array(),
		'trackback' => array(),
		'pingback'  => array(),
		'pings'     => array(),
	);

	$count = count( $comments );

	for ( $i = 0; $i < $count; $i++ ) {
		$type = $comments[ $i ]->comment_type;

		if ( empty( $type ) ) {
			$type = 'comment';
		}

		$comments_by_type[ $type ][] = &$comments[ $i ];

		if ( 'trackback' === $type || 'pingback' === $type ) {
			$comments_by_type['pings'][] = &$comments[ $i ];
		}
	}

	return $comments_by_type;
}

常见问题

FAQs
查看更多 >