开发者

How do I print a single comment thread in Drupal?

开发者 https://www.devze.com 2023-01-31 08:39 出处:网络
I want to make a page that contains a single comment AND all the replies to it.So far, no luck: I can call comment_render on the node and desired comment ID (cf also How do I print a single comment in

I want to make a page that contains a single comment AND all the replies to it. So far, no luck: I can call comment_render on the node and desired comment ID (cf also How do I print a single comment in drupal?), but that just gives me the comment, not the replies.

Digging through the comments table makes me think that a solution would have to hack its way through the cid and pid fields that implement the thread, but I don't see how to do that in a way that can be passed through pager_query to handle the possibility of a large number of repli开发者_Python百科es. Any thoughts out there? Thanks!


For future visitors: I got something working, which I think actually isn't too terrible:

1: Pull all the comments on the given node out of {comments}.

2: Walk through those comments, starting with CID: traverse the tree of replies to the original comment and put together an array of the starting CID and all the discovered replies.

3: Make a temporary table, selecting from {comments} just those whose NID is that of the starting node and whose CID is one of those found by walking the tree.

4: Hand this temporary table off to a hacked version of comment_render, which operates on the temporary table instead of {comments}.

5: Print the result.

6: Profit!

Or so it seems, anyway. It probably means tracking comment_render as new versions are released, but I'm guessing/hoping that it's pretty stable code by now. Thoughts about the relative wisdom of this are, of course, welcome.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号