How do I print a single comment in drupal?(如何在 drupal 中打印单个评论?)
问题描述
我想根据评论 ID 在 drupal 中打印单个评论.我怎样才能做到这一点?谷歌和其他来源没有给我任何结果.谢谢你.
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.
推荐答案
Eaton 的建议很好(除了它是 {comments}
,而不是 {comment}
)如果你需要像 core 一样显示评论,包括来自节点的信息.除了 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);
}
}
当然,受 comment.tpl.php
的启发,在模块的 hook_theme()
实现中定义这种特殊的注释格式.
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 中打印单个评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 drupal 中打印单个评论?


基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01