theNewDynamic / gohugo-theme-ananke

Ananke: A theme for Hugo Sites
https://gohugo-ananke-theme-demo.netlify.com/
MIT License
1.09k stars 1.12k forks source link

Show categories #620

Open melroy89 opened 1 year ago

melroy89 commented 1 year ago

You only list the tags of the Hugo posts. But Hugo also supports categories as taxonomies. Could you please also show them when viewing the post?

Example of the markdown page section with categories:

categories:
  - Beginner
  - Server
tags:
  - cicd
  - docker
  - free
ijsamuel commented 1 year ago

Yes - curious on how this can be done. When a post is added, the tags show at the bottom - how can the category also show?

ijsamuel commented 1 year ago

Figured it out. This can be further modified to customize the look.

  1. Added a new partial under layouts/partials called "categories.html" with the below code: <ul class="pa0"> {{ range .GetTerms "categories" }} <li class="list di"> <b>Categories: </b><a href="{{ .RelPermalink }}" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif"> {{- .LinkTitle -}} </a> </li> {{ end }} </ul>

  2. Then in layouts/_default, modified single.html by adding the categories above the {{ Content }} like this: {{- partial "categories.html" . -}}

Now the categories show up on the posts.