comment_get_recent

Versions
5 – 7
comment_get_recent($number = 10)

Find the most recent comments that are available to the current user.

Parameters

integer $number (optional) The maximum number of comments to find. Defaults to 10.

Return value

An array of comment objects or an empty array if there are no recent comments visible to the current user.

▾ 1 function calls comment_get_recent()

theme_comment_block in modules/comment/comment.module
Returns a formatted list of recent comments to be displayed in the comment block.

Code

modules/comment/comment.module, line 379

<?php
function comment_get_recent($number = 10) {
  $query = db_select('comment', 'c');
  $query->innerJoin('node', 'n', 'n.nid = c.nid');
  $query->innerJoin('node_comment_statistics', 'ncs', 'ncs.nid = c.nid');
  $query->addTag('node_access');
  $comments = $query
    ->fields('c')
    ->condition('ncs.comment_count', 0, '>')
    ->condition('c.status', COMMENT_PUBLISHED)
    ->condition('n.status', NODE_PUBLISHED)
    ->orderBy('ncs.last_comment_timestamp', 'DESC')
    ->orderBy('c.cid', 'DESC')
    ->range(0, $number)
    ->execute()
    ->fetchAll();

  return $comments ? $comments : array();
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.