【问题标题】:Get all Comment ID's within a Drupal node获取 Drupal 节点中的所有评论 ID
【发布时间】:2009-03-25 00:34:43
【问题描述】:

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

【问题讨论】:

标签: drupal drupal-comments


【解决方案1】:

我想你应该检查一下 comment_render 函数。

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

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

您可以先查询列出您需要订购的所有 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 函数中。但我试图修改它以供我使用。

现在我们有了我们想要的 node idcids。

这里是渲染工作;

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

foreach ($mycomment as $mycid)

comment_render($nid, $mycid)

}

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

【讨论】:

    【解决方案2】:

    您可以使用以下函数在 drupal 7 中为一个节点加载所有 cmets:

    comment_get_thread($node, $mode, $comment_per_page)

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

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

    【讨论】:

      【解决方案3】:

      更简单的解决方案:

      $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 的第二个参数将处理获取所有附加信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-20
        • 2014-01-23
        • 1970-01-01
        • 2015-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多