我想在我的单曲中找到一条路。php列出所有用户(显示名称)haven\'t 对当前帖子发表了评论。
我有一段代码,列出了have 已发表评论。。。
/**
* Retrieve a list of comment authors\' names.
*
* @param int $id Optional. Post ID.
* @param string $sep Optional. List separator.
* @return string|null Names list.
*/
function get_comment_authors_list( $id = 0, $sep = \', \' ) {
$post_id = $id ? $id : get_the_ID();
if ( $post_id ) {
$comments = get_comments( array(
\'post_id\' => $post_id,
\'status\' => \'approve\',
\'type\' => \'comment\',
) );
$names = array();
foreach ( $comments as $comment ) {
$name = $comment->comment_author;
if ( $comment->user_id ) {
$user = get_userdata( $comment->user_id );
$name = $user ? $user->first_name : $name;
}
$arr = explode( \' \', trim( $name ) );
if ( ! empty( $arr[0] ) && ! in_array( $arr[0], $names ) ) {
$names[] = $arr[0];
}
}
unset( $comments );
$sep = $sep ? $sep : \', \';
return implode( $sep, $names );
}
}
/**
* Display a list of comment authors\' names.
*
* @param int $id Optional. Post ID.
* @param string $sep Optional. List separator.
* @return null
*/
function the_comment_authors_list( $id = 0, $sep = \', \' ) {
echo get_comment_authors_list( $id, $sep );
}
/*
* Available parameters for the Shortcode:
* int post_id Optional. Post ID.
* string list_sep Optional. List separator.
*
* Usage examples:
* [comment_authors_list /]
* [comment_authors_list post_id="1" list_sep=" · " /]
*/
add_shortcode( \'comment_authors_list\', \'comment_authors_list_shortcode\' );
/**
* Shortcode callback function.
*
* @see get_comment_authors_list()
* @return string|null Names list.
*/
function comment_authors_list_shortcode( $atts = array() ) {
$atts = shortcode_atts( array(
\'post_id\' => 0,
\'list_sep\' => \'\',
), $atts );
return get_comment_authors_list( $atts[\'post_id\'], $atts[\'list_sep\'] );
}