From past couple of months, I have been trying to make Blogger commenting system look cool 😎 and beautiful. I have also shared different tricks to customize blogger comment system.
Today, I want to reverse the order of comments in blogger as I realized by default blogger displays oldest comments first and newest ones at the bottom.
I had couple of questions:
Can I change the order of comments in blogger? Can I display newer comments first and move old comments at the bottom? Do I need to write extra code of Javascript or manipulate with DOM?
Answer - Yes, it is possible 💪 to sort blogger comments from latest to oldest without writing a single line of Javascript.
Let me show you how.
Sorting Blogger comments from New to Old
Blogger provides some lines of code to display comments. If you open your theme HTML code, you can find this piece of code:
<b:loop values='data:post.comments' var='comment'>
Or,
<b:loop values='data:post.comments where (c => not c.inReplyTo or c.inReplyTo == 0)' var='comment'>
This line 👆simply loops through each comment for this post. To reverse the order of these comments you'll need a way to indicate you want to loop starting at the most recent comment and work your way through the older comments. But how? There is a way to do it natively in Blogger using reverse HTML tag.
Add reverse='1'
to above code.
Reverse='1' reverses the default order of comments in blogger and displays latest to oldest.
<b:loop reverse='1' values='data:post.comments' var='comment'>
Or,
<b:loop reverse='1' values='data:post.comments where (c => not c.inReplyTo or c.inReplyTo == 0)' var='comment'>
That is all. Now your comments are sorted from new to old. Happy Blogging! ✊
Any Questions? Leave a comment below. And do you want me to write more guides on customizing blogger commenting system? If yes, let me know.
Some cool articles to check next -