Wordpress评论框样式的读取文章或者页面评论数据自定义:wp_list_comments()

Wordpress评论框样式由wp-including下的comment.php和comment-template.php控制。一般在主题下的comment.php文件中引用读取wordpress文章或者页面评论数据:
wp_list_comments() 源代码位于 wp-includes/comment-template.php.

一般样式:
    wp_list_comments( array(
    'style' => 'ol',
    'short_ping' => true,
    'callback' => 'monseng_comments'
    ) );
    ?>

基本函数:
 
参数:
'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、使用回调函数来自定义评论的展示方式:
回调函数为mytheme_comment,你可以添加在你主题的functions.php文件中,函数方法如下:
//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-">
%s says:'), get_comment_author_link()) ?>
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);
    ?>

这样就实现了评论回复区的自定义。

#现在前往

精选留言

评论,Wordpress,comments,list
sample
2021-05-31
写留言
签到
投稿
QQ咨询
返回顶部