当前位置:首页 »“秋了秋”个人博客 » WP教程 » Wordpress自定义评论列表制作

Wordpress自定义评论列表制作

作者:秋了秋 发表时间:2015年04月12日

WORDPRESS系统本身自带有评论列表调用函数,只要一段代码(<?php wp_list_comments();?> )就可以实现评论列表的展示,大多数主题都是使用的默认调用函数,使用这个虽然增加了主题制作的方便性,但是它是调用系统给你定义的id和class,所以对于样式的修改带来麻烦,而且你也不敢保证wordpress的更新不会更换id和class,且自定义性较弱,需要加入一些东西比较麻烦,比如说给评论增加*认证,博主高亮,楼层显示,这无疑就要去修改wordpress系统wp-include下的comment-template.php模版,修改的东西随着更新又会消失。针对这一问题,我们需要替换评论列表的函数,在主题下的comments.php找到<?php wp_list_comments();?>找到这个代码,有的带了参数,如:<?php wp_list_comments(xxxx);?>把这句替换为以下代码即可:

<?php function qiuye_comment($comment, $args, $depth)
{ $GLOBALS['comment'] = $comment; ?>
<li class="comment" id="li-comment-<?php comment_ID(); ?>">
<div class="comment-body">
<div class="comment-author">
<?php if (function_exists('get_avatar') && get_option('show_avatars')) { echo get_avatar($comment, 48); } ?>
<?php printf(__('<cite class="fn">%s</cite>'), get_comment_author_link()); ?>
<div class="comment-meta commentmetadata">发表于:<?php echo get_comment_time('Y-m-d H:i'); ?> </div></div>
<div class="comment_content" id="comment-<?php comment_ID(); ?>">
<div class="comment_text">
<?php if ($comment->comment_approved == '0') : ?>
<span>你的评论正在审核,稍后会显示出来!</span><br />
<?php endif; ?><?php comment_text(); ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('reply_text' => '回复','depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
&nbsp;&nbsp;
<?php edit_comment_link('修改'); ?>
</div></div></div></div></li><?php } ?>
<?php wp_list_comments('type=comment&callback=qiuye_comment');?>

这样就层次分明了,想要修改哪里就修改哪里,还不快替换你的评论列表函数?样子见如下:

总共有: 1条评论
  1. zwepd.cn/ 网博客栈说:

    发鬼地方个好

    [15楼]中国福州市 Windows 7 | Chrome 63.0.32 回复
5
文章作者: “秋了秋”个人博客,本站鼓励原创。
转载请注明本文地址:http://netblog.cn/blog/323.html
目录: WP教程标签: 评论列表 17020次阅读

请求播放音乐,请点击播放

登 录
点击获取验证码
还没账号?点击这里