在 Shopify 中,如何按最近的评论设置排序顺序?



如何使最新的评论首先显示?我无法在文档中找到它,目前我的评论是无序的。

这是我的文章模板:

{% for comment in article.comments %}
<li id="{{ comment.id }}" class="comment{% unless number_of_comments > article.comments_count %}{% if forloop.first %} first{% endif %}{% endunless %}{% if forloop.last %} last {% endif %}">
{% include 'comment' %}
</li>
{% unless forloop.last %}

在我的评论中包括:

<div class="grid">
<div class="grid__item medium-up--one-quarter">
<span class="comment-author">{{ comment.author }}</span>
<span class="comment-date">
{{ comment.created_at | time_tag: format: 'month_day_year' }}
</span>
</div>
<div class="grid__item medium-up--three-quarters">
<div class="rte">
{% comment %}ly_code_replace_for_[ comment.content ]_begin{% endcomment %}{% include 'ly-content' with comment %}{{ ly_translation }}{% comment %}ly_code_replace_end{% endcomment %}
</div>
</div>
</div>

更新:为了解决这个问题,我必须添加:

{% assign artComments = article.comments | sort: "created_at" | reverse %}

您可以在for 循环标记中使用reversed参数:

{% for comment in article.comments reversed %}
... do your thing
{% endfor %}

最新更新