In-Reply-To and Infinite Replies

Over at OT, I have added a variation on automatic “In Reply To” commenting links, which I believe may once have been more common, and which some users find helpful in sorting out long discussions, especially in nested comment threads at “max depth,” and even more when an “Infinite Replies” capacity has been enabled.

Infinite Replies (IR)

I summarized “Infinite Replies” in my introductory post on them at OT as follows:

When comment thread “nesting” reaches maximum “depth” reply links will continue to appear underneath new comments, and the actual replies will appear at the bottom of the given sub-thread. ((Not precisely true: see discussion under IR2L.)) This solution as implemented will not be the ideal implementation – which would involve more complex dynamics and formatting – but will be a good start, at least relieving us on busy threads from having to scroll all the way to the top in order to reply to a comment far below.

Over the course of months in 2014-5, I kicked around various ways of achieving this effect with WordPress developer Bhagwad Jal Park, who had authored a simple hack for it, and also is the one who named the result “Infinite Replies” ((Obviously the replies aren’t infinite, but rather more open-ended or pervasive or something, but it’s kind of fun to think of them as infinite and of replies at max depth as entering the Infinite Zone.)), as described in his post in late 2013: “Allow Infinite Replies with WordPress Threaded Comments.”

Executing Bhagwad’s hack required committing a WordPress developer’s sin, hacking a WordPress core file, whose main practical drawback is the requirement that a site manager re-do the hack every time WordPress does a major update or update affecting the core file in question. The recommended – and better – practice is to add or modify whatever function or process in question via theme or plug-in, and there are almost always a range of choices available.

Bhagwad finally achieved his own non- or less-hacky solution via a method he described in detail in a later post, “Adding Infinite Replies in WordPress.” The solution that he details there requires 1) creating a substitute “Comment-Reply-Link” function and 2) adjusting it if necessary so that it works with the Javascript that locates comment reply boxes on a comment thread.

You can examine Bhagwad’s solution at the linked post. The solution I applied at OT was much simpler, since all it required was making an edit to a WordPress child theme, a non-sinful method for making such modifications. Doing so bypasses the lost-to-upgrade problem, which can affect themes in the same way it affects WP core files. Another alternative would be to develop a theme-independent plug-in, and the best solution would likely involve developing a full-fledged independent commenting system (comment “Walker” function or even more elaborate), but those are projects for a different day/month/season/year. ((Also, just in case it doesn’t go without saying, neither Bhagwad’s nor my solution will likely be useful to someone using a third-party commenting system like Disqus or Livefyre.))

At OT, all I had to do was locate the “comment_reply_link()” function, which on the Expound theme used at OT happens to be located in a special template-tags.php file. The key portion looked like this:

comment_reply_link( array_merge( $args,array(
    'depth' => $depth,
    'max_depth' => $args['max_depth'],
) ) )

Adding infinite replies turned out to consist of adding a space and two little characters to the max_depth line (a recursive solution of the sort beloved by programmers, which originated, in passing, in a StackExchange “answer” on a different question):

 /*
* "Infinite Replies" - let comment-reply-link continue to appear on all comments at max-depth
*/
comment_reply_link( array_merge( $args,array(
   'depth' => $depth,
   'max_depth' => $args['max_depth'] +1,
) ) );

Depending on how a given theme is constructed and written, this solution may have to be amended in different ways. In order, for instance, to apply it at this blog, whose theme does not deploy significant customizations of built-in WP commenting, I would need to write a new filter function or possibly a comment “Walker” function, a project for another day. ((The WP Codex outlines the process in relation to comments in its page on the wp_list_comments() function. Starting with the page on the so-called “Walker Class” may induce blackouts in beginners…))

Though Bhagwan wanted to avoid writing his own Walker, the eventual best solution will involve doing so, I expect. If done in a standards-compliant way, it would not interfere with typical theme commenting customizations accomplished on the level of styling/formatting, or by use of plug-ins, or by minimal additions to normal WP commenting functionality.

In Reply To Links (IR2L)

After adding Infinite Replies to OT, several users noticed what they experienced as a time-displacement confusion, since, in a give mono-columnar sub-thread of the sort that results at maximum depth, it is possible for particular comments to appear above other comments made earlier. In other words, contrary to my initial description, new comments do not always appear at the bottom of the new thread. Actually, what we’re seeing in such a long thread will be comments that in one sense are at different depths, but for display purposes are at the same depth.

For independent but overlapping reasons, some commenters also like being able to tell immediately what a given commenter is specifically replying to, and, especially in a long, complicated discussion, may also like to be able to find an original comment. Luckily enough for both purposes – if not necessarily a complete solution, especially with reference to an ideal “IR” display and functionality – the code snippet for “in reply to” links has been floating around in the WordPress ocean of snippets for years.

The example I happened to run across is written a little differently than in my normal PHP style, but it works, so why complain? Usually, the link is written out “in reply to,” but I wanted something more compact for OT. I also wrapped the addition in its own div + CSS class so I could style it:

<!-- add In Reply To Link -->

<div class="comment-irt">
    <?php if ($comment->comment_parent != '0') : ?>
    <a href="<?php
        $commentparent = get_comment($comment->comment_parent);
        $commentparentpage = get_page_of_comment($commentparent);
        echo htmlspecialchars(get_comment_link( $commentparent, array('page' => $commentparentpage) ) ); ?>
    "> to 
    <?php echo $commentparent->comment_author ; ?>
    </a>
    <?php endif; ?>
</div>

It was easier to add directly to the Expound Child template-tag.php file than it would or will be to add on this blog – probably by adding a filter function or in the context, as above, of writing a new comment Walker. Just to complete these notes for now, I styled the “comment-irt” div as follows:

/* Make In Reply To link kinda purty but discreet */

.comment-irt {
    display: inline-block;
    float: right;
    margin-top: -12px;
}

.comment-irt a {
    color: #cccccc;
    font-weight: 300;
    font-size: 12px;
    letter-spacing: 2px;
}

.comment-irt a:hover {
    font-weight: 500;
}

…producing this:

reply_to_link

You can view or try it on any thread at OT. (The above image happens to come from the “Why Nine Innings” comment thread.)

4 comments on “In-Reply-To and Infinite Replies

Commenting at CK MacLeod's

We are determined to encourage thoughtful discussion, so please be respectful to others. We also provide a set of Commenting Options - comment/commenter highlighting and ignoring, and commenter archives that you can access by clicking the commenter options button (). Go to our Commenting Guidelines page for more details, including how to report offensive and spam commenting.

  1. Hey, glad you managed to get this to work for your theme!

    I used the same “hack” to add a “parent comment” link – by just pre-pending it to the comment text as I wrote here:

    https://www.webhostinghero.com/wordpress-parent-comment-links/

    I’m also thinking that maybe the comment styles of Google+ and Facebook are pretty elegant. They have a effective “comment depth” of just 2 and seem to not have real problems with long discussions.

    Haven’t yet worked up the courage to implement that though!

    • Hey, Bhagwad.

      The code I used in the above is kind of “IRT Classic” – if you search for its constituent parts you’ll find them used in a lot of places. It may appear in the WordPress Codex somewhere, and I wonder if comment_parent wasn’t added to WP core for precisely this purpose.

      I like your version of IRT via function. In fact, I think I will very soon try a version of it to add IRT links to this blog. Once that’s accomplished, it ought to make for a cute little plug-in, assuming there isn’t one already in the repo I never noticed. (If you or someone else beats me to the punch, I’ll try it out here.)

      I’m not sure about Google+ and Facebook for long discussions – either at the sites themselves or in comment threads styled to emulate them – in part because I’ve never been in or attempted to follow one in such a situation, though I have been in long, un-threaded discussions that eventually became very burdensome to try to develop, since by comment 100 or 200 there may be several discussions going on at once, or threads that have been abandoned because they’ve just become to difficult to find and follow.

      Because the Ordinary Times site has a unique commenter community, featuring a number of intelligent, voluble, and polite yet argumentative souls, many of whom have been discussing political and cultural topics with each other for years now, the comments and sidebar and sidebar-to-the-sidebar discussions sometimes get long and involved, putting more or a premium on whatever enhancements you can think of: My first goal since I started working at OT was doing things that would make my own participation easier.

    • Thanks, Marc – I’ll take a look at it, though I’m a little confused by the description, specifically by what you mean by “2nd level thread,” since it sounds like you’re saying “not every comment on threads at depth 3, 4, etc.”

      Anyway, adding the reply links is good, and it’s cool if you’ve come up with a way to do it that doesn’t require editing or replacing template files, but I was as interested in, and eventually got to, extending threads “infinitely” (or unboundedly), so that really long ones don’t jam up confusingly wherever they end – was more of a concern at a busy blog where threaded conversations semi-regularly go into the hundreds of comments.

      https://ckmacleod.com/2015/08/25/the-snake-is-implemented-2/

1 Pings/Trackbacks for "In-Reply-To and Infinite Replies"
  1. […] snippets and explanations on IRTL and also on Infinite Replies available at my personal blog. […]

Commenter Ignore Button by CK's Plug-Ins

Leave a Reply

Your email address will not be published. Required fields are marked *

*