长沙快付新闻资讯
您当前的位置是: 首页->做网站知识->做网站

WordPress自定义评论列表

首发: 长沙快付 版权所有,未经许可严禁转载
WORDPRESS系统本身自带有评论列表调用函数,只要一段代码(<?php wp_list_comments();?> )就可以实现评论列表的展示,大多数主题都是使用的默认调用函数,使用这个虽然增加了主题制作的方便性,但是它是调用系统给你定义的id和class,所以对于样式的修改带来麻烦,而且你也不敢保证wordpress的更新不会更换id和class,且自定义性较弱,需要加入一些东西比较麻烦,比如说给评论增加v认证,博主高亮,楼层显示,这无疑就要去修改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');?>
这样就层次分明了,想要修改哪里就修改哪里,还不快替换你的评论列表函数?
  • 最新签约客户
  • 最新上线网站
为什么选择长沙快付公司?

8年专业做网站经验
帮助您解决各种需求,并得到满意方案

效果满意后付款
预付30%定金,效果让您满意后,付全款

资深用户体验设计师
秉承"一切以用户价值为依归"理念,重视用户体验,专为企业需求进行定制

采用国际标准结构建站
DIV+CSS国际标准构建网页,可有效提高网站访问速度、提高网站页面的可维护

实现网络营销[SEO]最大化
网站程序中融入SEO,有效降低企业成本

分享到: