Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show categories #620

Open
melroy89 opened this issue Feb 4, 2023 · 2 comments
Open

Show categories #620

melroy89 opened this issue Feb 4, 2023 · 2 comments
Milestone

Comments

@melroy89
Copy link
Contributor

melroy89 commented Feb 4, 2023

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
Copy link

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
Copy link

ijsamuel commented Mar 24, 2023

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.

@davidsneighbour davidsneighbour added this to the unplanned milestone Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants