function comment_get_display_ordinal

cis7 comment.module comment_get_display_ordinal($cid, $node_type)
cle7 comment.module comment_get_display_ordinal($cid, $node_type)
elmsmedia7 comment.module comment_get_display_ordinal($cid, $node_type)
icor7 comment.module comment_get_display_ordinal($cid, $node_type)
meedjum_blog7 comment.module comment_get_display_ordinal($cid, $node_type)
mooc7 comment.module comment_get_display_ordinal($cid, $node_type)

Get the display ordinal for a comment, starting from 0.

Count the number of comments which appear before the comment we want to display, taking into account display settings and threading.


$cid: The comment ID.

$node_type: The node type of the comment's parent.

Return value

The display ordinal for the comment.

See also


1 call to comment_get_display_ordinal()
comment_get_display_page in modules/comment/comment.module
Return the page number for a comment.


modules/comment/comment.module, line 1766
Enables users to comment on published content.


function comment_get_display_ordinal($cid, $node_type) {
  // Count how many comments (c1) are before $cid (c2) in display order. This is
  // the 0-based display ordinal.
  $query = db_select('comment', 'c1');
  $query->innerJoin('comment', 'c2', 'c2.nid = c1.nid');
  $query->addExpression('COUNT(*)', 'count');
  $query->condition('c2.cid', $cid);
  if (!user_access('administer comments')) {
    $query->condition('c1.status', COMMENT_PUBLISHED);
  $mode = variable_get('comment_default_mode_' . $node_type, COMMENT_MODE_THREADED);

  if ($mode == COMMENT_MODE_FLAT) {
    // For flat comments, cid is used for ordering comments due to
    // unpredicatable behavior with timestamp, so we make the same assumption
    // here.
    $query->condition('c1.cid', $cid, '<');
  else {
    // For threaded comments, the c.thread column is used for ordering. We can
    // use the vancode for comparison, but must remove the trailing slash.
    // See comment_view_multiple().
    $query->where('SUBSTRING(c1.thread, 1, (LENGTH(c1.thread) -1)) < SUBSTRING(c2.thread, 1, (LENGTH(c2.thread) -1))');

  return $query->execute()->fetchField();



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.