【函数介绍】
wp_list_comments()是用于读取wordpress文章或者页面评论数据的函数。
【函数使用】
$args
(array) (可选)函数参数条件选项.
默认:
null,
'max_depth' => '',
'style' => 'ul',
'callback' => null,
'end-callback' => null,
'type' => 'all',
'reply_text' => 'Reply',
'page' => '',
'per_page' => '',
'avatar_size' => 32,
'reverse_top_level' => null,
'reverse_children' => ''
); ?>
max_depth, per_page, 以及reverse_top_level 可以再后台“设置”=》“讨论”处设置。
per_page:每页显示数量
max_depth:最多嵌套
reverse_top_level:是否显示最新评论
$comments
(array) (可选) 通过get_comments查询得到的评论数据
默认: 返回get_comments函数的返回值.
【参数说明】
$avatar_size
(integer) (可选) 头像大小. 如果通过http://gravatar.com/ 获取的头像尺寸再 1 到 512像素.
默认: 32
$style
(string) (可选) 评论样式控制,你可以添加 ‘div’, ‘ol’, 或者’ul’ 来展示你的评论,如:
'div')); ?>or
'ol')); ?>默认: ‘ul’
$type
(string) (可选) 评论展现方式.可以是 ‘all’, ‘comment’, ‘trackback’, ‘pingback’, or ‘pings’. ‘pings’ 包含了’trackback’和’pingback’
默认: ‘all’
$page
(string) (可选) 当前页数.
默认: null
$reply_text
(string) (可选) 评论的回复链接. (可以通过函数get_comment_reply_link function 获取)
默认: ‘Reply’
$login_text
(string) (可选)用户必须登录后评论的提示信息.
默认: ‘Log in to Reply’
$callback
(string) (可选) 回调函数,通过回调函数来自定义你的评论展示方式。
Default: null
$end-callback
(string) (可选) 关闭评论后调用的自定义函数
Default: null
$reverse_top_level
(boolean) (可选)评论数据是否倒序显示
Default: null
$reverse_children
(boolean) (可选) 子评论数据是否倒序显示。
Default:null
【函数实例】
1、列出当前文章或者页面的评论数据:
2、使用回调函数来自定义评论的展示方式:
回调函数为mytheme_comment,你可以添加在你主题的functions.php文件中,函数方法如下:
//author by wordpress教程网(shouce.ren)
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
< id="comment-">
<div id="div-comment-" class="comment-body">
<?php printf(__('%s says:'), get_comment_author_link()) ?>
comment_approved == '0') : ?>
<a href="http://www.shouce.ren/api/view/a/comment_ID ) ) ?>">
$add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?><?php
}
3、将评论显示在文章或者页面中:
//author by wordpress教程网(shouce.ren) XXX,
'status' => 'approve' //Change this to the type of comments to be displayed
));//Display the list of comments
wp_list_comments(array(
'per_page' => 10, //Allow comment pagination
'reverse_top_level' => false //Show the latest comments at the top of the list
), $comments);
?>
【源代码】
wp_list_comments() 位于 wp-includes/comment-template.php.









