Get all comment IDs in Drupal node

I have a node in Drupal with a few comments. Is there an easy way to get the CID of each comment in node? In addition, there is a way to sort them by various parameters, chronology, commentary karma, etc. Thanks.

+3
source share
3 answers

I assume you should check the comment_render function.

But if you need your own sort option, it would be easier to do this with sql commands;

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

You can first make a request listing all cid on all you need to do,

$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 id cid s , .

;

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

foreach ($mycomment as $mycid)

comment_render($nid, $mycid)

}

, , .

+3

node 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');

+1

Simplified 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'] );
}

In our initial SQL query, we only need to get the comment identifier (cid), since the second comment_render parameter will process all the additional information.

0
source

Source: https://habr.com/ru/post/1705302/


All Articles