[Comments Module] Set ascending or descending order

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
kendo451

[Comments Module] Set ascending or descending order

Post by kendo451 »

The question: How to make Comments render in ascending or descending order?

I'm running the latest Comments Module on CMSMS 1.4.1.1.

The module help does not list any hooks that allow you to set the order that the comments are rendered in.  The short answer to my question would be if there is already a hook, that just isn't listed on the Comments Module help page.  Anyone know if there is an order variable for Comments?

Assuming there is not, then my next option is to reverse the order the comments are printed in by altering the {foreach} loop in the Display Template for the Comments Module.

The original form of the loop is like this:

Code: Select all

{foreach from=$items item=entry}
<li>
  
		{if $entry->author_email}
		<span class="author"><a class="author" href="mailto:{$enuthor_email|escape:"hexentity"}">{$entry->comment_author}</a></span>
		{else}
		<span class="author">{$entry->comment_author} says:</span>
		{/if}
		{if $entry->author_website}(<a href="{$entry->author_website}" target="_blank">{$entry->author_website}</a>){/if}
	{$entry->comment_data}
        <span class="date">{$entry->date}</span>
</li>
{/foreach}
Since {foreach} doesn't have the flexbility to count backwards, I tried replacing it with the following {section} loop instead:

Code: Select all

{section loop=$item name=entry step=-1}
<li>
  
		{if $entry->author_email}
		<span class="author"><a class="author" href="mailto:{$enuthor_email|escape:"hexentity"}">{$entry->comment_author}</a></span>
		{else}
		<span class="author">{$entry->comment_author} says:</span>
		{/if}
		{if $entry->author_website}(<a href="{$entry->author_website}" target="_blank">{$entry->author_website}</a>){/if}
	{$entry->comment_data}
        <span class="date">{$entry->date}</span>
</li>
</section}
This seemed to work, as it did produce a ul with the correct number of list items.  However, the items were blank.

This makes me think that changing the loop type messed up the variable calls in the body of the loop.

Does anyone have any suggestions on how to fix it?

Thanks,
Ken Griffith
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: [Comments Module] Set ascending or descending order

Post by RonnyK »

kendo451

Re: [Comments Module] Set ascending or descending order

Post by kendo451 »

Thanks, Ronny, but the thread you linked to doesn't actually solve the rendering order.  Furthermore, I would like to solve the problem without having to change any of the php files in the core, which is what that thread requires.

My (incomplete) method, only requires a change to the Comment Display Template.

The method I've started above should work, if I can make the variable calls for $item work with the new loop structure.

I could use some help from a better programmer to make the example above work properly.

Thanks,
Ken Griffith
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: [Comments Module] Set ascending or descending order

Post by tsw »

Not really tested...

Code: Select all

Index: Comments.module.php
===================================================================
--- Comments.module.php (revision 77)
+++ Comments.module.php (working copy)
@@ -27,7 +27,7 @@
 
        function GetVersion()
        {
-               return '1.8.2';
+               return '1.8.3';
        }
 
        function GetHelp($lang = 'en_US')
@@ -184,6 +184,9 @@
          $this->SetParameterType('content', CLEAN_NONE);
          $this->SetParameterType('redirecturl',CLEAN_NONE);
 
+      $this->SetParameterType('reverse',CLEAN_NONE);
+         $this->CreateParameter('reverse', '', $this->lang('help_reverse'));
+
                $this->CreateParameter('dateformat', '', $this->lang('helpdateformat'));
                $this->CreateParameter('localedateformat', '', $this->lang('helplocaledateformat'));
 
Index: lang/en_US.php
===================================================================
--- lang/en_US.php      (revision 77)
+++ lang/en_US.php      (working copy)
@@ -33,6 +33,7 @@
 $lang['options_updated'] = 'The options were successfully saved.';
 $lang['nocommentsfound'] = 'No comments found';
 $lang['help_akismet_check'] = '<b>Check for Spam</b> - Check this box to use Akismet module to detect spam. <b>Note: Using this feature requires that the CMSakismet module be installed.</b>';
+$lang['help_reverse'] = 'Reverse comment listing';
 $lang['author'] = 'Author';
 $lang['data'] = 'Comment text';
 $lang['email'] = 'Email';
Index: action.default.php
===================================================================
--- action.default.php  (revision 77)
+++ action.default.php  (working copy)
@@ -310,6 +310,10 @@
                }
        }
 
+    if(isset($params['reverse']) {
+        array_reverse($entryarray);
+    }
+
        $this->smarty->assign_by_ref('items', $entryarray);
 
        #Display template
Locked

Return to “CMSMS Core”