如何在 Drupal 中打印单个评论线程?
我想创建一个包含单个评论及其所有回复的页面。到目前为止,没有运气:我可以在节点和所需的评论 ID 上调用 comment_render (另请参见 如何在 drupal 中打印一条评论?),但这只是给我评论,而不是回复。
深入研究注释表让我认为解决方案必须通过实现线程的 cid 和 pid 字段来破解,但我不知道如何以可以通过 pager_query 传递来处理的方式做到这一点大量回复的可能性。有什么想法吗?谢谢!
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 replies. Any thoughts out there? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于未来的访问者:我得到了一些工作,我认为这实际上并不太可怕:
1:从 {comments} 中提取给定节点上的所有评论。
2:从 CID 开始遍历这些评论:遍历原始评论的回复树,并将起始 CID 和所有发现的回复组成一个数组。
3:制作一个临时表,从{comments}中仅选择NID为起始节点且CID为通过遍历树找到的那些之一的那些。
4:将此临时表交给comment_render的破解版本,该版本对临时表而不是{comments}进行操作。
5:打印结果。
6:利润!
至少看起来是这样。这可能意味着在新版本发布时跟踪 comment_render ,但我猜测/希望它现在是相当稳定的代码。
当然,欢迎对此相对智慧的思考。
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.