Home > Shopify Development > Save posts by date, tags, and categories

How to save posts by date, tags, and categories in Shopify

Sam Nguyen
Sam Updated: February 21, 2024

Share:

Drive 20-40% of your revenue with Avada
avada email marketing

You are meeting troubles with saving posts by dates, tags, and categories? Don’t be worried because we are here to give you the detailed instruction on how to address your issue with Jekyll Archives. Jekyll Archives allows you to generate pages listing posts by their tags, dates, and categories.

However, please keep reading our instructional writing on how to save posts by date, tags, and categories to find out the solution.

How to save posts by date, tags, and categories

1. Installation

Step 1: Create a Gemfile

To get started, there may be some definitions that we should clarify.

A Gem is a collection of code that we can include in Ruby projects. It enables us to take codes from anyone and drop them into your project. There are several functions that Gems can perform like:

  • Pagination
  • Interact with APIs like Github
  • Converting a Ruby object to JSON

For your information, Jekyll is a Gem similar to a lot of Jekyll plugins including jekyll-archives, jekyll-seo-tag, and jekyll-feed.

A Gemfile is the dependency management system of Ruby. That is to say, it is a list of Gems that a Ruby project needs to run.

Also, we need to run bundle install to create a gemfile.lock file and download the Gems in gemfile.lock. Please run:

gem install bundler

Step 2: In your Gemfile, add jekyll-archives to the jekyll_plugins group:

source 'https://rubygems.org'

gem 'jekyll', '3.3.1'

group :jekyll_plugins do
  gem 'jekyll-archives'
end

Step 3: Run bundle install

2. Configuration

All configuration is set in _config.yml that is under the arrchives key. However, the default configuration is set to the code given below:

jekyll-archives:
  enabled: []
  layout: 'archive'
  permalinks:
    year: '/:year/'
    month: '/:year/:month/'
    day: '/:year/:month/:day/'
    tag: '/tag/:name/'
    category: '/category/:name/'

Enabled

It describes which types of archive are enabled. All options include all or the array of any combination of month, year, day, tags, categories.

enabled: all
enabled:
  - categories
enabled:
  - year
  - month
  - tags

Layout

To be used if there is no type-specific layout which is set.

layout: archive

Type specific layout

Layouts for particular types of archives.

layouts:
  year: year-archive
  month: month-archive
  day: day-archive
  tag: tag-archive-layout

Customize the format of the permalink of the archive pages.

permalinks:
  year: '/archives/year/:year/'
  month: '/archives/month/:year-:month/'
  tag: '/archives/tag/:name/`

3. Usage

You are able to link to the permalink you have just set up whenever the plugin is set up. There is a category called jekyll-plugins on this site so I am able to link to it like this:

<a href="/categories/jekyll-plugins/">Plugins</a>

All the categories and links to their archive pages can be outputted by looping of site.categories:


<ul>
{% for category in site.categories %}
  {% assign category_name = category[0] %}
  <li>
    <a href="/category/{{ category_name | slugify }}/">{{ category_name | replace: "-", " " }}</a>
  </li>
{% endfor %}

Conclusion

Please read the instruction above carefully so that you can save posts in your favorite way.


Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

Stay in the know

Get special offers on the latest news from AVADA.