Display posts by tags or category

Is it possible to display posts by tags or a single category per post, so that I could have an archive with headings, something like this:

Apples

This is a post title, January 1st 2021

An earlier post, December 20th, 2020

Oranges

My latest post about oranges, June 5th, 2021 …

Asked 2 years ago • Improve this question
3 replies

First, you will want to fork an editable version of your template, if you haven't already.

Then add a new view to your template, copying the archives.html view as a starting point.

Into your new view, paste the following template code which will list all of your tags in alphabetical order, and all of the posts associated with each tag!

{{#allTags}}
  <h3>{{tag}}</h3>
  {{#entries}}
    <a href="{{{url}}}">{{title}}</a><br>
  {{/entries}}
{{/allTags}}

The template code above should replace the {{#allEntries}} or the {{#archives}} block, depending on which template you copied archives.html from.

Please let me know if you would like me to go into more detail about any of these steps, or if you have any questions!

Answered 2 years ago · Improve this answer

How does one call up the new view? (eg if I have a file named category-archive.html, what would be the hyperlink that will show its contents?)

Answered 2 years ago · Improve this answer

By default, category-archive.html has the URL /category-archive.html.

You can change this in your template's configuration file, which is called package.json. For example, consider the package.json property for archives.html.

Let's say you want category-archive.html to have the URL /categories. You would add the following to the views key in package.json:

...
    "category-archive.html": {
      "url": "/categories"
    },
...

Does that make sense? Please let me know if you have any questions about this or anything else

Answered 2 years ago · Improve this answer

Markdown allowed

Question or feedback?

Contact us
How to password-protect a site? Thumbnails on social media? Title in menu vs title on page? Home Page Alt Text for Images

On this page