Hey there--

Ok, I have a tricky question.

I understand that the posts in forums are actually simply comments, the same as a comment on any other node. Got it. Great. That's a nice trick in the code, and creating an entirely different look is easy via CSS.

Great. Good. Fine.

I also understand how to set the order (most recent first or last) on comments and how to designate whether they're threaded or not.

Again, great, good fine.

BUT, what if I want the comments on forums to order in a different way than the comments on other nodes? Is this possible at all?

Because I really want a reverse order on the forums (most recent comment first), but on other nodes, like blog entries etc, I want chronological order (most recent last).

Any ideas?

Comments

vm’s picture

flatcomment.module found in the repository may help with this.

sinker’s picture

Not quite sure what the purpose of that module is--non-threaded views arranged chronologically are built into Drupal.

Anyway, that's not what I'm looking for. I installed it and while it would be fine if I wanted some comments to run threaded and others not, that's not my desire.

What I need is a way to have comments in forum posts to run MOST RECENT ----> LEAST RECENT, but comments on, say, blog entries to run LEAST RECENT ----> MOST RECENT.

Since there's only one setting for ordering comments, you can have one set running one way and one running the other. Flatcomment follows the system settings for chronology, so unfortunately it's not the solution.

Any ideas anyone?

Sakrecoer’s picture

I was actualy wondering the same thing...
I want comments on page nodes to go most recent on top
and forum nodes comments to go most recent bellow, as in a proper forum....

Looking forward to get help!

Drupal guys: I love what you do by the way!

open your mind open the source
express yourself, share your tools

dvessel’s picture

Not really possible. Drupal 6 fixes this I believe.

With 5, it's coded for *all* comment listings while 6, it's per node type.

duke_of_fluke’s picture

I was looking for a solution for this but couldn't find any posts. I'm quite new to drupal (just working on my first site) so if there is a better way let me know but this is what I did

The function comment_render() is responsible for rendering the comments on a node, so I made a copy of this which rather than use the site defaults for ordering and mode took them in as a parameter.

Added this code to my custom functions module (just an alteration of comment_render())

function user_functions_comment_render($node, $cid = 0, $order = 2, $mode = 2) {
  global $user;

  $output = '';

  if (user_access('access comments')) {
    // Pre-process variables.
    $nid = $node->nid;
    if (empty($nid)) {
      $nid = 0;
    }
        
    $comments_per_page = _comment_get_display_setting('comments_per_page');

    if ($cid) {
      // Single comment view.
      $query = 'SELECT c.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.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';
      $query_args = array($cid);
      if (!user_access('administer comments')) {
        $query .= ' AND c.status = %d';
        $query_args[] = COMMENT_PUBLISHED;
      }

      $result = db_query($query, $query_args);

      if ($comment = db_fetch_object($result)) {
        $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
        $links = module_invoke_all('link', 'comment', $comment, 1);

        foreach (module_implements('link_alter') as $module) {
          $function = $module .'_link_alter';
          $function($node, $links);
        }

        $output .= theme('comment_view', $comment, $links);
      }
    }
    else {
      // 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.cid 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.cid';
        }
        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 .= '<div class="indented">';
            $last_depth++;
          }
          else {
            while ($comment->depth < $last_depth) {
              $divs--;
              $output .= '</div>';
              $last_depth--;
            }
          }
        }

        if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
          $output .= theme('comment_flat_collapsed', $comment);
        }
        else if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
          $output .= theme('comment_flat_expanded', $comment);
        }
        else if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
          $output .= theme('comment_thread_collapsed', $comment);
        }
        else if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
          $output .= theme('comment_thread_expanded', $comment);
        }
      }
      for ($i = 0; $i < $divs; $i++) {
        $output .= '</div>';
      }
      $output .= theme('pager', NULL, $comments_per_page, 0);

      if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
        $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
      }
    }

    // If enabled, show new comment form if it's not already being displayed.
    $reply = arg(0) == 'comment' && arg(1) == 'reply';
    if (user_access('post comments') && node_comment_mode($nid) == COMMENT_NODE_READ_WRITE && (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_BELOW) && !$reply) {
      $output .= comment_form_box(array('nid' => $nid), t('Post new comment'));
    }

    $output = theme('comment_wrapper', $output);
  }

  return $output;
}

I'm using the Advanced Forum module which makes themeing the modules a bit easier. In the forum template we want to use our new function rather than comment_render so at the end of the forum-thread.tpl.php put the following

                  <?php
	        	    if (function_exists('comment_render') && $node->comment) {
	        	     print user_functions_comment_render($node, $node->cid);
	        	     $node->comment = NULL;
	        	    }
                  ?>

This will render the comments using our new function then blank the comment variable so that the comments won't be posted again (a tip I read somewhere by Michelle (I think)). Assigning the comment variable to NULL was not working for me so I had to hack the node module to not display comments for forums but I'm not sure why it didn't work. So hopefully it should work for you guys