-3

Good morning. How can I show blog comments, created with bloggers, in reverse order: from the latest to the oldest. Only for some posts. thank you

2

2 Answers 2

2

You can count the length of comment and loop it to 0 and use the result for index example

<!-- Get the Post -->
<b:loop values='data:posts' var='post'>

    <!-- It will loop from the length of comments to 0 to be used for index -->
    <!-- comment.length to 0 -->
    <b:loop values='data:post.comments.length &quot; to 0&quot;' var='i'>
        <data:comments[i].author/>
        <hr/>
    </b:loop>

</b:loop>
0

This can be implemented only when using non-threaded comments. To configure your theme to use non-threaded comments rather than threaded comments, you will have to make changes in the <b:includable id='comment_picker' var='post'> block present inside the Blog widget. This block's code will be changed to -

<b:includable id='comment_picker' var='post'>
    <b:if cond='data:post.commentSource == 1'>
        <b:include data='post' name='comments'/>
    </b:if>
</b:includable>

After that, to reverse the order of comments find the following b:loop statement -

<!-- In v2 themes, present inside <b:includable id='comments' var='post'> -->
<b:loop values='data:comments' var='comment' >


<!-- In v3 themes, present inside <b:includable id='commentList' var='comments'> -->
<b:loop values='data:post.comments' var='comment'>

Add the reverse attribute to the b:loop statement, so that code looks like -

<!-- In v2 themes-->
<b:loop values='data:comments' var='comment' reverse='1'>


<!-- In v3 themes-->
<b:loop values='data:post.comments' var='comment' reverse='1'>

To make this applicable on some of the posts, you will have to wrap the b:loop statement with a b:if statement (which uses the condition of either Post URL or PostID)

6
  • The line does not exist: <b:includable id='commentList' var='comments'> There is not even the word: "commentList" Commented Jun 26, 2017 at 15:34
  • @VincenzoIavazzo commentList is only present in v3 themes that were released on March 20, 2017 (Refer to blogger.googleblog.com/2017/03/…) If you use any one of those new themes, then only will you likely come across commentList in the code Commented Jun 27, 2017 at 6:58
  • If I replace: <b:includable id='comments' var='post'> with: <b:loop values='data:comments' var='comment' reverse='1' The error appears: The element type "b:loop" must be terminated by the matching end-tag "</b:loop>" So I replaced: </b:includable> with: </b:loop> And this time the error appears: The widget with id "Blog1" cannot contain element: "b:loop". A widget can only contain b:includable elements. did I do something wrong? thank you Commented Jun 28, 2017 at 10:31
  • @VincenzoIavazzo You do not need to replace <b:includable id='comments' var='post'> with <b:loop values='data:comments' var='comment' reverse='1' > . Instead you need to replace <b:loop values='data:comments' var='comment' > with <b:loop values='data:comments' var='comment' reverse='1' > (or as you will notice, simply add the reverse='1' attribute to that b:loop statement) as well as change the comment_picker's b:includable tag to use non-threaded comments Commented Jun 29, 2017 at 8:14
  • Works with a blog created in 2017. It does not work with a blog created in 2008. Do you know why? Anyway, that's fine. thank you so much. You are a true expert. Commented Jun 29, 2017 at 14:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.