Is it possible to sort comments first on top

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
FinnK

Is it possible to sort comments first on top

Post by FinnK »

Is it possible to sort comments first on top and new comments at the bottom?
pgoneill

Re: Is it possible to sort comments first on top

Post 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
pgoneill

Re: Is it possible to sort comments first on top

Post 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.
Last edited by pgoneill on Fri Dec 01, 2006 9:15 pm, edited 1 time in total.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Is it possible to sort comments first on top

Post 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
pgoneill

Re: Is it possible to sort comments first on top

Post 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. :)
Locked

Return to “CMSMS Core”