4
votes

Is there an easy way to get the comments of a node programmatically in Drupal 7?

3

3 Answers

5
votes

Check out the function comment_get_thread(), it may be of use to you.

1
votes

If you don't want to write a code then you can override the node with The panel's node template and by creating a variant in it you can add comment thread in the variant. And I think it is very easier way to do this.

0
votes

In Drupal 7 you can use the below code to get all the comments of a node using node ID

$nid = 2; // node ID
    $comments = db_select('comment')
              ->fields('comment', array('name','subject'))
              ->condition('nid', $nid, '=')
              ->execute()
              ->fetchAssoc();
    foreach($comments as $comment) {
        print your comments here
    }

In Drupal 6 you can use the comment_render() ;