Custom Tags Page
Updated on
Last site update: 8 May 2024
This site uses the Blank theme which uses on list page template for section pages, taxonomy pages and taxonomy term pages. I wanted specific customization of this, to make a basic tag cloud and no pagination.
How to
Created a new template in layouts/tags/list.html
. There is lots of choice to choose from. This doesn’t affect the categories page which still uses the layouts/_default/list.html
page.
The code for the new page is:
1{{ define "main" }}
2
3<main class="list-page">
4
5 {{ if or .Title .Content }}
6 <div>
7 {{ with .Title }}<h1>{{ . }}</h1>{{ end }}
8 {{ with .Content }}<div>{{ . }}</div>{{ end }}
9 </div>
10 {{ end }}
11
12<ul class="tags-list">
13 {{ range .Pages.ByTitle }}
14 <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
15 {{ end }}
16</ul>
Modify the sidebar
The sidebar was set up to change depending on whether it’s section was something or nothing (like home, links and about pages). For the tags page the section is tags. To include this I added an or to the if statement:
{{ if or (eq .Section "") (eq .Section "tags") }}
<h2>Latest Posts</h2>
<ul>...
{{ partial "sidebar.html" . }}
{{ end }}
```