我后台设置的嵌套评论为最大10,然后没完没了的评论与回复一旦超过10层就再不能回复了,顿时感到无语与蛋疼。

无奈,折腾吧~把最大嵌套数改为10000吧,没人能互相对侃超过1万层吧?相当于无限嵌套了。

修改主题下comments.php文件,找到:



  1. <?php wp_list_comments('type=comment&callback=mytheme_comment&end-callback=mytheme_end_comment'); ?>  



修改为:



  1. <?php wp_list_comments('type=comment&callback=mytheme_comment&max_depth=10000'); ?>  



 

很多人的无限嵌套是嵌套2层(后台改为嵌套2),然后所有回复都堆积在第二层。

可是我还想嵌套10。

嵌套越多会一直向右靠,(我的是向中间靠),结果肯定会受不了,最好是让超过10层保持和前面层数位置一样就行。

在functions.php内回调评论函数内找到类似:



  1. <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">  



修改为:



  1. <li <?php comment_class('clearfix'); ?>   

  2. <?php   

  3. if( ($depth > 9 && $depth < 10000)){ echo ' style="margin-left:-11px;margin-right:-11px;"';} ?> id="comment-<?php comment_ID() ?>" >  




说明:-11PX是因为我的主题每嵌套就缩进11PX,数值请根据你的主题进行修改,因为我的嵌套是左右都缩进,所以是margin-left:-11px;margin-right:-11px;,如果你的主题只是向右缩进的话,请去掉margin-right:-11px;)

但是评论一多就不知道谁在回复谁了,最好是在前面加个“@XX”,这样就知道是在回复谁了。

用 jQuery 实现点击回复之后显示@用户名的效果:



  1. jQuery(document).ready(function($){ //Begin jQuery   

  2.     $('.reply').click(function() {   

  3.     var atid = '"#' + $(this).parent().attr("id") + '"';   

  4.     var atname = $(this).prevAll().find('cite:first').text();   

  5.     $("#comment").attr("value","<a href=" + atid + ">@" + atname + " </a>").focus();   

  6. });   

  7.     $('.cancel-comment-reply a').click(function() { //点击取消回复评论清空评论框的内容   

  8.     $("#comment").attr("value",'');   

  9. });   

  10. })  //End jQuery  



 


最后修改:2019 年 06 月 06 日
收藏不易,如果感觉对你有用,请随意打赏支持下