1

Topic: How to reverse the order of comments?

So glad I upgraded to Wolf, all the little improvements are really beginning to show now!

However there's one slight tweak I'd like to make - in my old install of Frog, older comments appeared at the top with newest ones at the bottom.

I get a lot of conversation in my comments so I'd like to change the comment order back to this if I am able to, how would I go about doing this?

Thumbs up 0

2

Re: How to reverse the order of comments?

In the backend or the frontend?

In the admin backend there is currently no way to influence the order in which the comments are sorted.

In the frontend, the comments() function that is used in the snippet, returns an array of all comments so you can reorder them any way you want.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution or see our financial report first.

3

Re: How to reverse the order of comments?

Thank you, yes I meant the front end, sorry for leaving that info out.

I'm sorry, I don't know much php, I've found the snippet you're referring to but I don't know what to put in to sort it, can you help?

Thumbs up

4

Re: How to reverse the order of comments?

Valeska wrote:

... in my old install of Frog, older comments appeared at the top with newest ones at the bottom.

Hi Valeska - I noticed the same thing, but I'm not sure when the change in sort crept in. I think the "expected" sort for "comments" is to have the new comments added at the bottom, while for "guestbooks" it is to have new items added at the top.

Here Wolf's current default comment-each snippet with the reverse-sort (from oldest-to-newest) added:

<p><strong><?php echo $num_comments = comments_count($this); ?></strong> comment<?php if ($num_comments != 1) { echo 's'; } ?></p>
<?php $comments = comments($this); ?>
<ol class="comments">
<?php krsort($comments); // This line reverses the Wolf default new-to-old sort ?>
<?php foreach ($comments as $comment): ?>
  <li class="comment">
    <p><?php echo $comment->body(); ?></p>
    <p> &#8212; <?php echo $comment->name(); ?> <small class="comment-date"><?php echo $comment->date(); ?></small></p>
  </li>
<?php endforeach; // comments; ?>
</ol>

I think one of the things somewhere on the "to-do" list is overhaul the comments plugin, but this should take care of things for the moment!

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

5

Re: How to reverse the order of comments?

Thank you both for your help, that works a treat. smile

Thumbs up 0

6

Re: How to reverse the order of comments?

David wrote:

I think one of the things somewhere on the "to-do" list is overhaul the comments plugin, but this should take care of things for the moment!

Correct David. I've grouped them together so before we hit 1.0 final, all core plugins should've had an overhaul.

And you're welcome Valeska.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution or see our financial report first.

7

Re: How to reverse the order of comments?

Hello,
I have tried the reverse tipp (#3) with WolfCMS 0.7.7, but unfortunately the order is still old-to-new, means the oldest is on the top.
Is there a way have the newest comment/entry on the top ?

Regards
bongo

Thumbs up 0

8

Re: How to reverse the order of comments?

bongo wrote:

I have tried the reverse tipp (#3) with WolfCMS 0.7.7, but unfortunately the order is still old-to-new, means the oldest is on the top.

That's odd: in my out-of-the-box test install of 0.7.7, comments sort with the newest at the top of the list, oldest at the bottom. Including the "krsort()" line reverses that order, so oldest is at top, and newest at bottom.

Could you post here the current contents of your "comment-each" snippet? If you leave OUT this line:

<?php krsort($comments); // This line reverses the Wolf default new-to-old sort ?>

then you should have the comments in the order you want.

(UPDATE: is it because the numbering of the comments go 1... 2... 3... etc.? They always go that order, because of the <ol> ... </ol>, of course.)

Last edited by David (2013-05-15 22:27)

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

9

Re: How to reverse the order of comments?

Arg, yes you are right.
I do not know, why it was in the first way wrong.

My actual code:

<p><strong><?php echo $num_comments = comments_count($this); ?></strong> Kommentar<?php if ($num_comments != 1) { echo 'e'; } ?></p>
<?php $comments = comments($this); ?>
<ol class="comments">
<?php foreach ($comments as $comment): ?>
  <li class="comment">
    <p><?php echo nl2br($comment->body()); ?></p>
    <p> &#8212; <?php echo $comment->name(); ?> <small class="comment-date"><?php echo $comment->date(); ?></small></p>
  </li>
<?php endforeach; // comments; ?>
</ol>

and it is working correctly.

Sorry for confusion.

Thumbs up 0

10

Re: How to reverse the order of comments?

bongo wrote:

and it is working correctly.

Sorry for confusion.

Ah, phew! wink No problem. I had some interesting techniques for "reverse counting", big_smile if that was what you needed. Glad it is working correctly, though!

Using Wolf CMS professionally and for profit? Please consider supporting Wolf financially. Thanks!

11

Re: How to reverse the order of comments?

Hello,
I want to come back to this core-plugin.
Was the sort order changed in 8.3.1 ?

I have again the fact, that my oldest comment is on top and the newest on at the botton.
(It is fresh installation)

Have also tried <?php krsort($comments); // This line reverses the Wolf default new-to-old sort ?> on top of the snippet comment-each, but this does not solve the issue.

<p><strong><?php echo $num_comments = comments_count($this); ?></strong> Kommentar<?php if ($num_comments != 1) { echo 'e'; } ?></p>
<?php $comments = comments($this); ?>
<ol class="comments">
<?php foreach ($comments as $comment): ?>
  <li class="comment">
    <p><?php echo nl2br($comment->body()); ?></p>
    <p> &#8212; <?php echo $comment->name(); ?> <small class="comment-date"><?php echo $comment->date(); ?></small></p>
  </li>
<?php endforeach; // comments; ?>
</ol>

regards
rs

Add: The sort order in the backend (admin view) is newest-oldest, in the front-end oldest-newest.

Last edited by bongo (2015-10-26 14:47)

Thumbs up

12

Re: How to reverse the order of comments?

Retrieve the comments this way, it will have your comments sorted from newest to oldest:

<?php
$args = array('where' => 'is_approved=1', 'order' => 'is_approved, created_on DESC');
$comments = Comment::find($args);
?>

You might have a interest in using a pagination class,
Wolf is bundeld with one but I used this one instead:
https://www.wolfcms.org/forum/topic231.html

13

Re: How to reverse the order of comments?

Many thanks for the code - it is working perfectly.

Thanks again.

Thumbs up