• Hi!

    If WP is configured to display only two levels of comment threading the reply-button is only visible at the first comment in one thread:

    – comment
    – reply-button
    — comment
    — comment
    — comment
    — comment
    — comment

    But this is confusing if you want to answer to the last comment. So, how do I configure wp to display the button after every comment AND limiting wp to only 2 levels of comment-threading? Just like this:

    – comment
    – reply-button
    — comment
    – reply-button
    — comment
    – reply-button
    — comment
    – reply-button
    — comment
    – reply-button

    Any idea? Is there a hook or parameter I can use?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Marc Toensing

    (@marcdk)

    I’ll answer this myself. Here is a javascript solution with jQuery. It will append a reply link to the last li element of the children ul.

    $('.commentlist > li > div .reply').each(function() {
    		var reply = this;
    		var lastchild = $(this).parent().parent().children('.children').children(":last");
    		$(reply).clone().appendTo(lastchild);
    	});

    could you please guide me where do I put this script?

    Very interesting!

    Hozyali – If you’re still around, don’t use this code block below (as it goes about things in the wrong way), but just for example purposes:

    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $('.commentlist > li > div .reply').each(function() {
    		var reply = this;
    		var lastchild = $(this).parent().parent().children('.children').children(":last");
    		$(reply).clone().appendTo(lastchild);
    	});
    });
    </script>
    </head>

    Note, as is, this will still jump the form all the way back up to the parent comment when the cloned reply button is clicked (and the comment-reply.js is active).

    So, this is pretty neat.
    Building off of what MarcDK has created…

    If you’d like the reply form to drop in below the last child instead of popping up to the top parent comment, as well as change “Reply” to “Reply to this thread”, try this:

    var lastchild = $(this).parent().parent().children('.children').children(":last");
    var lastchildattr = $(this).parent().parent().children('.children').children(":last").children().attr("id");
    var targetdiv = $(this).parent().parent().children('.children').children(":last").children().children('.reply');
    var continuethread = $(this).html().replace(/comment\-(\d+)/g, lastchildattr).replace('>Reply<', '>Reply to this thread<');
    $(targetdiv).replaceWith('<div class=\"reply\">' + continuethread  + '</div>');

    It looks totally absurd, but this is how it would be done using the TwentyTen theme, which has a commenting nest like so:

    <ol class="commentlist">
      <li class="depth-1" id="li-comment-1">
        <div id="comment-1">
          (all that comment's data and divs)
        </div>
        <ul class='children'>
          <li class="depth-2" id="li-comment-2">
            <div id="comment-2">
              (all that comment's data and divs)
            </div>
          </li>
        </ul>
      </li>
    </ol>

    Because comment_reply_link is a little silly in that it will dump empty divs where the reply link should go, we can take advantage of this and replace it for the last child.

    Remember, this is only for comments with one level of threading (depth 2).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how to display comment reply-button after every comment in 2 levels threads?’ is closed to new replies.