wp_list_comments()
wp_list_comments( string|array $args = array(), WP_Comm…
wp_list_comments( string|array $args = array(), WP_Comment[] $comments = null )
显示注释列表。
Displays a list of comments.
目录锚点:#说明#源码#笔记
说明(Description)
用于评论.php列出特定帖子的评论的模板。另请参见#另请参阅WP_Query->注释
源码(Source)
/**
* List comments.
*
* Used in the comments.php template to list comments for a particular post.
*
* @since 2.7.0
*
* @see WP_Query->comments
*
* @global WP_Query $wp_query
* @global int $comment_alt
* @global int $comment_depth
* @global int $comment_thread_alt
* @global bool $overridden_cpage
* @global bool $in_comment_loop
*
* @param string|array $args {
* Optional. Formatting options.
*
* @type object $walker Instance of a Walker class to list comments. Default null.
* @type int $max_depth The maximum comments depth. Default empty.
* @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
* @type string $callback Callback function to use. Default null.
* @type string $end-callback Callback function to use at the end. Default null.
* @type string $type Type of comments to list.
* Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
* @type int $page Page ID to list comments for. Default empty.
* @type int $per_page Number of comments to list per page. Default empty.
* @type int $avatar_size Height and width dimensions of the avatar size. Default 32.
* @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'.
* @type bool $reverse_children Whether to reverse child comments in the list. Default null.
* @type string $format How to format the comments list.
* Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
* @type bool $short_ping Whether to output short pings. Default false.
* @type bool $echo Whether to echo the output or return it. Default true.
* }
* @param array $comments Optional. Array of comment objects.
*/
function wp_list_comments( $args = array(), $comments = null ) {
global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
$in_comment_loop = true;
$comment_alt = $comment_thread_alt = 0;
$comment_depth = 1;
$defaults = array(
'walker' => null,
'max_depth' => '',
'style' => 'ul',
'callback' => null,
'end-callback' => null,
'type' => 'all',
'page' => '',
'per_page' => '',
'avatar_size' => 32,
'reverse_top_level' => null,
'reverse_children' => '',
'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
'short_ping' => false,
'echo' => true,
);
$r = wp_parse_args( $args, $defaults );
/**
* Filter the arguments used in retrieving the comment list.
*
* @since 4.0.0
*
* @see wp_list_comments()
*
* @param array $r An array of arguments for displaying comments.
*/
$r = apply_filters( 'wp_list_comments_args', $r );
// Figure out what comments we'll be looping through ($_comments)
if ( null !== $comments ) {
$comments = (array) $comments;
if ( empty($comments) )
return;
if ( 'all' != $r['type'] ) {
$comments_by_type = separate_comments($comments);
if ( empty($comments_by_type[$r['type']]) )
return;
$_comments = $comments_by_type[$r['type']];
} else {
$_comments = $comments;
}
} else {
if ( empty($wp_query->comments) )
return;
if ( 'all' != $r['type'] ) {
if ( empty($wp_query->comments_by_type) )
$wp_query->comments_by_type = separate_comments($wp_query->comments);
if ( empty($wp_query->comments_by_type[$r['type']]) )
return;
$_comments = $wp_query->comments_by_type[$r['type']];
} else {
$_comments = $wp_query->comments;
}
}
if ( '' === $r['per_page'] && get_option('page_comments') )
$r['per_page'] = get_query_var('comments_per_page');
if ( empty($r['per_page']) ) {
$r['per_page'] = 0;
$r['page'] = 0;
}
if ( '' === $r['max_depth'] ) {
if ( get_option('thread_comments') )
$r['max_depth'] = get_option('thread_comments_depth');
else
$r['max_depth'] = -1;
}
if ( '' === $r['page'] ) {
if ( empty($overridden_cpage) ) {
$r['page'] = get_query_var('cpage');
} else {
$threaded = ( -1 != $r['max_depth'] );
$r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
set_query_var( 'cpage', $r['page'] );
}
}
// Validation check
$r['page'] = intval($r['page']);
if ( 0 == $r['page'] && 0 != $r['per_page'] )
$r['page'] = 1;
if ( null === $r['reverse_top_level'] )
$r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
if ( empty( $r['walker'] ) ) {
$walker = new Walker_Comment;
} else {
$walker = $r['walker'];
}
$output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r );
$wp_query->max_num_comment_pages = $walker->max_pages;
$in_comment_loop = false;
if ( $r['echo'] ) {
echo $output;
} else {
return $output;
}
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.7.0 | wp-includes/comment-template.php | 1 | 14 |
笔记(Notes)
如果您使用的是WordPress4.9.6或更高版本,并且没有显示“评论正在等待审核”警报。
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!