如何在drupal打印单个评论? [英] How do I print a single comment in drupal?
问题描述
我想根据它的评论ID在drupal打印一个单独的评论。我该怎么做? Google和其他来源没有让我失望。谢谢。
I want to print a individual comment in drupal based on it's comment ID. How can I do this? Google and other sources have yielded me nothing. Thank you.
推荐答案
伊顿的建议很好(除了 {comments}
如果您需要像核心一样显示评论,包括来自节点的信息,则 {comment}
)。除了 modules / comment / comment.tpl.php
中的默认theme_comment实现不使用$ node。
Eaton's suggestion is good (except it's {comments}
, not {comment}
) if you need to display the comment like core does it, including the info coming from the node. Except the default theme_comment implementation in modules/comment/comment.tpl.php
makes no use of $node.
但是,我做的略有不同,因为如果你需要提取一个注释,用 comment.tpl.php
提供的正常内容格式显示它可能会不适用
However, I'd do it slightly differently, because if you need to extract a single comment, displaying it with the normal content formatting provided by comment.tpl.php
is likely to be inappropriate.
function print_comment($cid) {
$sql = "SELECT * FROM {comment} c WHERE c.cid = %d";
if ($comment = db_fetch_object(db_rewrite_sql(db_query($sql, $cid), 'c'))) {
return theme('my_special_comment_formatting', $comment);
}
}
当然,定义这个特殊的commment格式在你的模块的 hook_theme()
实现,灵感来自于什么 comment.tpl.php
。
And of course, define this special commment formatting in your module's hook_theme()
implementation, inspired by what comment.tpl.php
does.
2014-02更新:请注意,这是一个2009年的问题/答案。在Drupal 8中,您只是不想访问假设的底层SQL数据库(并且不会这样做,而是使用DBTNG),但只需使用以下内容:
2014-02 UPDATE: note that this is a 2009 question/answer. In Drupal 8, you just don't want to access the hypothetical underlying SQL database (and would not do it like this anyway, but use DBTNG), but just use something like:
if ($comment = entity_load('comment', $cid)) {
return entity_view($comment, $view_mode);
}
这篇关于如何在drupal打印单个评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!