Wordpress评论框样式的读取文章或者页面评论数据自定义:wp_list_comments()
Wordpress评论框样式由wp-including下的comment.php和comment-template.php控制。一般在主题下的comment.php文件中引用读取wordpress文章或者页面评论数据:
wp_list_comments() 源代码位于 wp-includes/comment-template.php.
一般样式:
基本函数:
1、列出当前文章或者页面的评论数据:
wp_list_comments() 源代码位于 wp-includes/comment-template.php.
一般样式:
基本函数:
函数实例使用:
参数:
'walker'=> 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'=>'',
'format'=>'html5',//或'xhtml'如果没有'HTML5'主题支持
'short_ping'=> false,// 3.6版本以后支持
'echo'=> true //布尔值,默认为true
1、列出当前文章或者页面的评论数据:
2、使用回调函数来自定义评论的展示方式:
//author by wordpress 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-">} comment_approved == '0') : ?>
$add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
3、将评论显示在文章或者页面中:
//Gather comments for a specific page/post
$comments = get_comments(array(
'post_id' => 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);
?>
这样就实现了评论回复区的自定义。
'style' => 'ol',
'short_ping' => true,
'callback' => 'monseng_comments'
) );
?>