Is it possible to reverse the order in which comments appear?

Norman Hills January 11, 2012

Bizarre request I know, but, I've been asked if it is possible to reverse the order of comments, ie.e. have the most recent at the top?

12 answers

1 accepted

19 votes
Answer accepted
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 11, 2012

You can do that client-side with a quick JavaScript hack...

Browse to Confluence Admin | Look & Feel | Custom HTML

Add this to At the end of the HEAD:

<script>
  AJS.toInit(function () {
    $comments = AJS.$('#page-comments'); 
    $comments.children().each(function (i,li) {
$comments.prepend(li);
}); }); </script>

Check the related blogpost for more tips :)

 

 

Norman Hills January 11, 2012

Thanks Dave, that did it.

Cheers

Norman

David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 11, 2012

No problem. If it worked, please mark it as correct :-)

Like Peter Adrial likes this
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 11, 2012

Also, if you want to allow the sort order to be changed, update the JavaScript to something like...

function reverseCommentOrder () {
  var $comments = AJS.$('#page-comments'); 
  $comments.children().each(function(i,li){$comments.prepend(li)});
}

AJS.toInit(function ($) {

  reverseCommentOrder();

  $('#comments-section-title').append(
'<a id="page-comments-reverse" href="#">(Reverse Order)</a>'
); $('#page-comments-reverse')
.css({ 'color':'#999','font-size':'0.65em'})
.click(function (e) { reverseCommentOrder(); e.preventDefault(); }); });

 

 

Like # people like this
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 11, 2012

This doesn't change the ordering in any nested comments -- I'm not really sure what the correct behaviour would be there. Thoughts?

Norman Hills January 11, 2012

Actually it sorta makes sense this way, the top level comments are presented in revese order and the replies are nested in reply order under the original - this seems pretty clear to me, I don't think I'd want the replies reversed as well.

David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
January 11, 2012

As I suspected. I couldn't really figure out what else would work.

Sean King
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2012

This works great for the first comment, but what about the subcomments underneath if people reply?

Sibel Yasar July 20, 2020

Hi, 

How can I get to the area Confluence Admin | Look & Feel | Custom HTML???

Thanks in advance

Sibel

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 20, 2020

Click on the admin cog, then look for look and feel, and custom html in the admin menu.

Like Sibel Yasar likes this
Victor Prasad July 21, 2020

For the sort order, anyway I can do that for only 1 space?

 

Thanks,

 

V

Like Sibel Yasar likes this
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 21, 2020

Sure, try this:

<script>

var mySpaceKey = 'EXAMPLE'; // Change this to the space key for the 1 space
AJS.toInit(function(){
if (AJS.params.spaceKey == mySpaceKey) { $comments = AJS.$('#page-comments'); $comments.children().each(function(i,li){$comments.prepend(li)});
} }); </script>
Like Sibel Yasar likes this
Sibel Yasar July 21, 2020

Thank you David!

3 votes
George Lewe (LSY)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2015

Indeed, the above solution only sorts the top level comments, not the sub comments. The reason is that only the top comment container has an identifier ("page-comments"). Such a global identifier can only be assigned to something that is always present. That is not the case for the sub-comments. So the sub-comments IDs are created on the fly and a solution like the above cannot know them beforehand of course.

Also, inserting the toggle link into the comment block has the flaw that it is removed when Confluence re-creates it after a new comment is added. Only a page refresh will make it appear again.

Other than that it works. Here is a solution how you can do this with a user macro so you can apply it to certain pages only by adding it onto the page.

## Macro title: Reverse Comments
## Macro body processing: No macro body
##
## Created by: George Lewe
## Created on: 2015-11-06
##
## This macro toggles page comments sort order
##
## @noparams
<script>
function rev(i, el) {
   $comments = AJS.$('#page-comments');
   $comments.prepend(el)
}
function reverseCommentOrder() {
   if (AJS.$('meta[name=ajs-form-name]').attr("content") != "editcommentform"){
      $comments = AJS.$('#page-comments');
      $comments.children().each(rev)
   }
}
AJS.toInit(function() {
   if($("#page-comments-reverse").length == 0) {
      AJS.$('#comments-section-title').append('<a id="page-comments-reverse" href="#" onclick="reverseCommentOrder();" style="color: #999; font-size: 0.65em;">[Toggle order...]</a>;');
   }
});
</script>
Victor Prasad April 27, 2016

where do would I insert this in a Space?

I am using 5.7.1.

Thanks!

 

George Lewe (LSY)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 4, 2017

The solution above is a page macro. It only applies to the page when you insert it. It is not space-wide.

Ian February 8, 2018

 I have placed the above code in the template of my user macro but when I save the page where the macro is it spits out the code and thus not ordering the comments?

How can I make the code be executed and not spit on the page?

Arti Kumar August 30, 2018

Did you figure this out?

George Lewe (LSY)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2018

Hi all,

I noticed that the editor here replace < with &lt, and > with &gt; in the code I provided. I edited the code section accordingly.

We still use that macro successfully. The user macro is set to "No macro body".

Best regards,
George

2 votes
Ronald Horner January 12, 2012

If you want to do this per space simply wrap it in {html} tags and place it in the custom header area: Space Admin -> Look And Feel -> Themes -> Configure Theme -> Header.

{html}
<script>
  AJS.toInit(function(){
    $comments = AJS.$('#page-comments'); 
    $comments.children().each(function(i,li){$comments.prepend(li)})
  });
</script>
{html}

Sibel Yasar July 21, 2020

Thank you Ronald !

1 vote
Ronald Horner February 25, 2013

This solution will handle new comments and replies to those comments

&lt;script&gt;
AJS.toInit(function(){
   if (AJS.$('meta[name=ajs-form-name]').attr("content") != "editcommentform" &amp;&amp; AJS.$('meta[name=ajs-form-name]').attr("content") != "threadedcommentform"){
      // Only reverse comments if you're not editing one of them
      $comments = AJS.$('#page-comments');
      $comments.children().each(function(i,li){$comments.prepend(li)});
    }
});
&lt;/script&gt;

0 votes
Victor Prasad July 21, 2020

Is this still viable for v 6.15.9 and above?

The Custom HTML inserted via the Admin console - does not seem to be working, but per space it does!

David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 21, 2020

Try now. I've just updated my old answers from 2012 - when Atlassian migrated the content from the old community (answers.atlassian.com), some html was mistakenly escaped.

Victor Prasad July 21, 2020

Thanks David!  

Really appreciate that!

 

Is that the same for the one with the choice of sort order?  add <script> tags?

 

V

0 votes
Jazon Reyes December 23, 2018

I'm not sure if this thread is still alive. I tried all the codes above, they all work. The thing is, everytime i enter a new comment, it is still displayed at the bottom. Any possible way that the newly entered comment(without refreshing the page) can appear on top as well?

0 votes
Victor Prasad April 27, 2016

Can I do that at just the Space Level, not a a global change?

Using v 5.7.1 Space Admin -> Look And Feel -> Themes -> Configure Theme -> Header does not exist.  I get the option of current theme or choose new theme and confirm.

I notice there is a Blog Layout in the Space Tool->Look and Feel->Blog Post Layout

Guess I can just put that in there?

0 votes
Robert Nordstrom January 16, 2015

Is it possible to reverse the comments order in the On Demand version of Confluence? We have 145 comments On one of our meeting notes page that grows daily… Scrolling to the bottom is becoming a bit of a pain. Thanks, Robert

karthik ses September 27, 2017

Hi Robert,

 

Any update on this issue . Please let us know, we are also searching for the same

Robert Nordstrom September 27, 2017

No, Karthik.

We have found no solution for reversing the sort order in the On Demand/cloud version of confluence. This is just one of the many limitations that we found since moving to the cloud instance. Seems like it should be a relatively minor thing to fix. Apparently, it's not high on the Atlassian scorecard.

karthik ses October 4, 2017

Hi Robert,

But we need to get by adding java script on header side, I think It is also not work out. We are finding any changes. Please suggest if you have any alternate method.

Thanks

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 4, 2017

There is no way to do it on Cloud.  AS you say, you need to change or add some javascript.  Which you can't do on Cloud.

0 votes
Sean King
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2012

This works great for the first comment, but what about the subcomments underneath if people reply?

0 votes
Mike McCracken June 25, 2012

This still has issues when you try and reply to a comment. Can anyone help?

Is there an issue to have Atlassian make this part of the code functionality?

Thanks

0 votes
Mike McCracken April 25, 2012

I am having the same issue with the Documentation theme in Confluence 4.1.9. I cannot edit comments. It brings up the editor, does not show the existing comment an does not give you a cursor. The preview button does not work either.

0 votes
Aviram Gabay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 21, 2012

Hi, I am using confluence V3.5 .

I tried to use David's solution which worked great but now it seems that

I am unable to reply on an existing comment using rich text editor, only by wiki markup (test on Chrome).

did someone else had this issue? is there a solution for this?

David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
March 23, 2012

I've not tried this in Confluence 3.5 only 4.x. Sorry.

David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 11, 2012

Try this to fix the comment edit/reply problem...

<script>
  AJS.toInit(function ($) {
    if ($('meta[name=ajs-form-name]').attr("content") != "editcommentform"){
      // Only reverse comments if you're not editing one of them
      $comments = $('#page-comments');
      $comments.children()
.each(function (i, li) {
$comments.prepend(li);
}); } }); </script>

 

 

Mike McCracken June 12, 2012

This is excellent David. Seems to work.

So the complete script is:

&lt;script&gt;
function reverseCommentOrder(){
    if (AJS.$('meta[name=ajs-form-name]').attr("content") != "editcommentform"){
      // Only reverse comments if you're not editing one of them
      $comments = AJS.$('#page-comments');
      $comments.children().each(function(i,li){$comments.prepend(li)});
    }
}

AJS.toInit(function(){

  reverseCommentOrder();

  AJS.$('#comments-section-title').append('&lt;a id="page-comments-reverse" href="#"&gt;(Reverse Order)&lt;/a&gt;');
  
  AJS.$('#page-comments-reverse').css({ 'color':'#999','font-size':'0.65em'}).click(function(e){
    reverseCommentOrder();
    e.preventDefault();
  });
});
&lt;/script&gt;

Steve Schoo September 6, 2016

Has anyone attempted something similar with Questions? A reverse sort or a way of maintaining Question order is what I'm looking for.

thejpkotor February 7, 2017

Is there a way to just add the reverse link without changing the default order? 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events