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:
You can view or try it on any thread at OT. (The above image happens to come from the “Why Nine Innings” comment thread.)
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!