Sensible comment handling.
UPDATE: you also need to overide theme_comment_folded to provide paging — otherwise when you try to click through to a folded comment that is not in the first page, it sends you to the wrong listing. This is a copy of a comment I posted on the “Drupal Usability: Comment Configuration” Lullabot article: There’s a fairly simple cut-n-paste hack to make collapsed comments function in a usable manner. I haven’t tested this edit fully for compatibility, in particular, I’m not sure what it does when it spans pages, but in theory I don’t see any issues, unless there’s someone who actually finds the single comment view useful. 1. drop the if ($cid) conditional branch from comment_render(). This is pretty much a code appendix, from what I can tell. 2. Replace that big ol’ honking block of if elses with the following switch statement: cid?theme(‘comment_flat_expanded’, $comment):theme(‘comment_flat_collapsed’, $comment); break; case COMMENT_MODE_FLAT_EXPANDED: $output .= theme(‘comment_flat_expanded’, $comment); break; case COMMENT_MODE_THREADED_COLLAPSED: $output .= $cid==$comment->cid?theme(‘comment_thread_expanded’, $comment):theme(‘comment_thread_collapsed’, $comment); break; case COMMENT_MODE_THREADED_EXPANDED: $output .= theme(‘comment_thread_expanded’, $comment); break; } ?> 3. Enjoy typical comment behavior instead of WTF. The whole function now reads: nid; if (empty($nid)) { $nid = 0; } $mode = _comment_get_display_setting(‘mode’); $order = _comment_get_display_setting(‘sort’); $comments_per_page = _comment_get_display_setting(‘comments_per_page’); // Multiple comment view $query_count = ‘SELECT COUNT(*) FROM {comments} WHERE nid = %d’; $query = ‘SELECT c.cid as 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.picture, u.data, c.score, c.users, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d’; $query_args = array($nid); if (!user_access(‘administer comments’)) { $query .= ’ AND c.status = %d’; $query_count .= ’ AND status = %d’; $query_args[] = COMMENT_PUBLISHED; } if ($order == COMMENT_ORDER_NEWEST_FIRST) { if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { $query .= ’ ORDER BY c.timestamp DESC’; } else { $query .= ’ ORDER BY c.thread DESC’; } } else if ($order == COMMENT_ORDER_OLDEST_FIRST) { if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { $query .= ’ ORDER BY c.timestamp’; } else { /* ** See comment above. Analysis learns that this doesn’t cost ** too much. It scales much much better than having the whole ** comment structure. */ $query .= ’ ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))’; } } // Start a form, for use with comment control. $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args); if (db_num_rows($result) && (variable_get(‘comment_controls’, COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get(‘comment_controls’, COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) { $output .= drupal_get_form(‘comment_controls’, $mode, $order, $comments_per_page); } $divs = 0; $last_depth = 0; drupal_add_css(drupal_get_path(‘module’, ‘comment’) .’/comment.css’); while ($comment = db_fetch_object($result)) { $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->depth = count(explode(‘.’, $comment->thread)) - 1; if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) { if ($comment->depth > $last_depth) { $divs++; $output .= ‘