How to display all posts with certain tags?


I want to have pages like http://localhost:1313/tags/hypotheses/ and http://localhost:1313/tags/experiments/ which display lists of posts with tags hypotheses and experiments, respectively. In addition, http://localhost:1313/post/ should work as it does now (displays the summaries of the last 7 posts).

Currently, I have the following code in layouts/_default/list.html:

{{ define "head" }}
<link rel="stylesheet" href='{{ "css/list.css" | absURL }}'>
{{ end }}

{{ define "main" }}
<main id="main" class="archive">
  {{ range where site.RegularPages "Type" "post" | first 7 }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
    {{ .Summary }}
  {{ end }}
{{ end }}

http://localhost:1313/post/ works fine (displays what it should). But

  1. http://localhost:1313/tags/hypotheses/ and
  2. http://localhost:1313/tags/experiments/

also display the last 7 posts instead of only posts with the correct tags.

Question 1

I assume I need to modify layouts/_default/list.html so that it works differently depending on the URL.

If the URL is /post it does what it does now (display the latest 7 posts).

If the URL is /tags/<someTag> then it executes a different piece of code which displays all posts with tag <someTag>.

Is this correct?

Question 2

I’m not the first person who wants to display a list of posts filtered by their tags. Where can I find an example for the list.html file which does that?

Thanks in advance

For now, all list of items are being rendered by _default/list.html,

Please have a look at the template lookup order for Taxonomy. You can create layouts/_default/taxonomy.html .You may also refer Taxonomy templates for taxonomy specific features.