Page 1 of 1

Is it possible to sort comments first on top

Posted: Tue Jun 20, 2006 9:18 pm
by FinnK
Is it possible to sort comments first on top and new comments at the bottom?

Re: Is it possible to sort comments first on top

Posted: Thu Nov 30, 2006 9:26 pm
by pgoneill
I'm wondering this very thing.  If anyone knows of a way to reverse the sorting of the comments, I'm all ears! ;D

Re: Is it possible to sort comments first on top

Posted: Fri Dec 01, 2006 9:12 pm
by pgoneill
OK, so I'll take that as a no.  :-\

Here's what I'm trying now in the comments display template (trying to "fake it" by getting a descending set of numbers to make the reader aware which is the first item, since the module spits them out backwards):

Code: Select all

  <dl>
  {php}$initialize = count($items);{/php}
  {foreach from=$items item=entry}
    <dt class="clearfix">
      <span class="counter">{counter start="$initialize" direction='down'}</span>
      {if $entry->author_email}
        <a href="mailto:{$entry->author_email|escape:"hexentity"}">{$entry->comment_author}</a>
      {else}
        {$entry->comment_author}
      {/if}
       said...<br /><span class="date">{$entry->date}</span></dt>
    <dd>{$entry->comment_data}</dd>
  {/foreach}
  </dl>
Obviously, this doesn't work.  Otherwise I wouldn't need to post it.

If anyone can provide a suggestion...basically I need to find the length of the $items array and use that as the start of the counter.

Re: Is it possible to sort comments first on top

Posted: Fri Dec 01, 2006 9:24 pm
by Dee
Looking at the source code of action.default.php it seems the comments are retrieved with this query:

Code: Select all

$query = "SELECT comment_id, comment_author, comment_data, comment_date, author_email, author_website FROM ".cms_db_prefix()."module_comments WHERE page_id = ".$pageid." AND module_name = '".$modulename."' AND active = 1 ORDER BY comment_date desc";
Change

Code: Select all

ORDER BY comment_date desc
at the end of that line to

Code: Select all

ORDER BY comment_date asc
and they should show the other way around.

Regards,
D

Re: Is it possible to sort comments first on top

Posted: Fri Dec 01, 2006 9:35 pm
by pgoneill
Sweet.

I ended up faking it (showing a descending series of numbers) by assigning a variable to smarty:

Code: Select all

$initializecount = count($entryarray);
$this->smarty->assign_by_ref('initializecount', $initializecount);
and then:

Code: Select all

  {foreach from=$items item=entry}
    <dt class="clearfix"><span class="counter">{$initializecount}</span>{if $entry->author_email}<a href="mailto:{$entry->author_email|escape:"hexentity"}">{$entry->comment_author}</a>
{else}{$entry->comment_author}{/if} said...<br /><span class="date">{$entry->date}</span></dt>
    <dd>{$entry->comment_data}</dd>
  {assign var=initializecount value=$initializecount-1}
  {/foreach}
Your way is much better, though. :)