获取 Drupal 节点内的所有评论 ID

发布于 2024-07-15 04:17:30 字数 98 浏览 5 评论 0原文

我在 Drupal 中有一个节点,其中有一些评论。 有没有一种简单的方法来获取节点内每个评论的 CID? 另外,有没有办法按各种参数、时间顺序、评论的业力等对它们进行排序。谢谢。

I have a node in Drupal with a few comments. Is there an easyish way to get the CID of every comment within the node? Also, is there a way to sort them by various parameters, chronology, karma of the comment etc. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

弱骨蛰伏 2024-07-22 04:17:30

我想你应该检查 comment_render 函数。

但如果你需要自己的排序参数,使用 sql 命令会更容易;

检查:http://api.drupal.org/api/function/comment_render/6< /a>

您可以先进行查询,列出您需要订购的所有 cid;

$myquery = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.picture, u.data, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid
= %d ORDER BY c.uid ASC';

$myresult = db_query($myquery)

该查询存在于 comment_render 函数中。 但我尝试修改它以供我使用。

现在我们已经按照我们想要的顺序获得了节点 IDcid

这是渲染工作;

while ($mycomments = mysql_fetch_row($myresult)){

foreach ($mycomment as $mycid)

comment_render($nid, $mycid)

}

我还没有测试过这个,但我希望它有帮助。

I suppose you should check the comment_render function.

But if you need your own sort parameter, it'd be easier to do it using sql commands;

Check: http://api.drupal.org/api/function/comment_render/6

You can first make a query listing all the cid's on whatever you need to order;

$myquery = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.picture, u.data, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid
= %d ORDER BY c.uid ASC';

$myresult = db_query($myquery)

This query exists on the comment_render function. But I tried to modify it for my use.

Now we have the node id and the cids in the order we wanted.

Here is the rendering work;

while ($mycomments = mysql_fetch_row($myresult)){

foreach ($mycomment as $mycid)

comment_render($nid, $mycid)

}

I haven't tested this one, but I hope it helps.

带刺的爱情 2024-07-22 04:17:30

您可以使用以下函数加载 drupal 7 中节点的所有注释:


comment_get_thread($node, $mode, $comment_per_page)

请查看此处的文档: http ://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_get_thread/7

它还讨论了默认排序参数。 然而,这并没有为您提供一种简单的方法来引用评论。 我只会使用视图来实现这一点。 然后可以使用hook_node_view禁用默认评论显示,并添加views_embed_view('my_view', 'my_display');

You can load all comments for a node in drupal 7 using the function:


comment_get_thread($node, $mode, $comment_per_page)

Check out the documentation here: http://api.drupal.org/api/drupal/modules%21comment%21comment.module/function/comment_get_thread/7

It also discusses the default sort parameter. This does not however give you an easy way to resort the comments. I would just use views for that. Then you can use hook_node_view to disable the default comment display and add views_embed_view('my_view', 'my_display');

北方的韩爷 2024-07-22 04:17:30

更简单的解决方案:

$sql = "SELECT cid FROM {comments} WHERE nid=%d ORDER BY timestamp DESC";

$resource = db_query($sql, $node->nid);
while( $row = db_fetch_array( $resource ) ) {
  print comment_render( $node->nid, $row['cid'] );
}

我们最初的 SQL 查询只需要获取评论 ID (cid),因为 comment_render 的第二个参数将处理获取所有附加信息。

Simpler solution:

$sql = "SELECT cid FROM {comments} WHERE nid=%d ORDER BY timestamp DESC";

$resource = db_query($sql, $node->nid);
while( $row = db_fetch_array( $resource ) ) {
  print comment_render( $node->nid, $row['cid'] );
}

Our initial SQL query only needs to fetch the comment ID (cid) as comment_render's second parameter will handle fetching all the additional information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文