Repositioning node comments

A strange quirk in Drupal 6 hard-codes comment rendering into the node module. This makes it quite difficult to reposition comments, for instance under a set of tabs in the node template. Attempting this brings you crashing into the most dreaded rampart of Drupal theming; moving something out of it's vertical stack:
comments displayed as tab
comment_render($node) can easily be placed in your node template, but how on earth can the original display be removed? comment_render() is called by node_show(), which contains this nugget:

if (function_exists('comment_render') && $node->comment) {
  $output .= comment_render($node, $cid);

Ouch. (Thankfully, this has been fixed in Drupal 7.)

While it's tempting to fake it with jQuery, or CSS positioning, there is a way to fix this by overriding the page callback for node rendering. Here's a quick module that implements this solution:

 * Implementation of hook_menu_alter().
 * Override the page callback for nodes, so that we can render nodes
 * without comments.  comment_render() will be called via the node template.
function comment_unrender_menu_alter(&$items) {
  $items['node/%node']['page callback'] = '_comment_unrender_node_page_view';
 * Generate a page displaying a single node, without its comments.
 * @see node_show()
function _comment_unrender_node_show($node, $cid, $message = FALSE) {
  if ($message) {
    drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp))));
  $output = node_view($node, FALSE, TRUE);
  // Update the history table, stating that this user viewed this node.
  return $output;
 * Menu callback; view a single node.
 * @see node_page_view()
function _comment_unrender_node_page_view($node, $cid = NULL) {
  return _comment_unrender_node_show($node, $cid);


Interesting. The talk module uses a different technique: it changes the value of $node->comment via hook_nodeapi(). (BTW I should have clarified, those are jQuery tabs, not Drupal's "local task" menus).

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>, <java>, <php>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Ready for transformation?