'how to filter blog posts by dates in shopify
I have a logic on shopify that determines the date of publication of blog posts, and also determines the number of posts for the corresponding date.
But I have a question, how can I filter posts by received dates? Maybe need to somehow configure the link to the filter? Please any help!
Here is the complete code:
{% capture month %}{{ 'now' | date: "%B" }}{% endcapture %}
{% capture year %}{{ 'now' | date: "%Y" }}{% endcapture %}
{% for i in (1..12) %}
{% case month %}
{% when 'January' %}{% assign previous_month = 'December' %}
{% when 'February' %}{% assign previous_month = 'January' %}
{% when 'March' %}{% assign previous_month = 'February' %}
{% when 'April' %}{% assign previous_month = 'March' %}
{% when 'May' %}{% assign previous_month = 'April' %}
{% when 'June' %}{% assign previous_month = 'May' %}
{% when 'July' %}{% assign previous_month = 'June' %}
{% when 'August' %}{% assign previous_month = 'July' %}
{% when 'September' %}{% assign previous_month = 'August' %}
{% when 'October' %}{% assign previous_month = 'September' %}
{% when 'November' %}{% assign previous_month = 'October' %}
{% when 'December' %}{% assign previous_month = 'November' %}
{% endcase %}
{% assign blogPresent = 0 %}
{% for article in blogs[blog.handle].articles %}
{% capture date %}
{{ article.published_at | date: "%B %Y" }}
{% endcapture %}
{% assign checkDate = month | append: ' ' | append: year %}
{% if date contains checkDate %}
{% assign blogPresent = 1 %}
{% endif %}
{% endfor %}
{% if blogPresent == 1 %}
<a href="" class="link-bar__link link--animated">{{ month }} {{year}}</a>
{%- assign count_date = 0 -%}
{% for article in blogs[blog.handle].articles %}
{% capture date %}
{{ article.published_at | date: "%B %Y" }}
{% endcapture %}
{% assign checkDate = month | append: ' ' | append: year %}
{% if date contains checkDate %}
{% assign count_date = count_date | plus: 1 %}
{% endif %}
{% endfor %}
<span class="blogs-count">{{ count_date }}</span>
{% endif %}
{% assign month = previous_month %}
{% endfor %}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
