Current Situation: I use Hugo and the Hugo coder theme to maintain a private website including a blog. On the website, I have a “Blog” section that internally corresponds to the folder structure content → posts where in posts I gather all posts without any further subfolders. The layout of the blog and its posts is done in the theme folder themes/hugo-coder/layouts/ . In the front matter of each post, I specify tags and categories. Right now, clicking on blog on the website displays all blog posts ordered by date and with the header Posts.
Objective: I would like to split that one list in 3 - 4 lists being side by side over several rows (i.e. 2 lists side by side, then below them again two lists side-by-side), each one having another header, i.e. category, where the category is derived from one of the categories that I specify in the front matter of the blog post (e.g. the first one).
Attempt: I got inspiration to solve this issue by looking at the questions here and here though it didn’t work out properly. More specifically, in \themes\hugo-coder\layouts I have the folder /posts/ with the three files li.html, list.html and single.html where I somehow have to modify the first two to change it – how do I achieve this?
Thank you for your suggestion. Unfortunately, it doesn’t work. The list of posts disappears completely and I got a blank page without any blog posts left (though with the appropriate header, footer, …). I used the following code and I know that all blog posts have either of these category names, i.e. there is no blog posts that might go missing here.
{{ define "title" }}
{{ .Title }} · {{ .Site.Title }}
{{ partial "math.html" . }}
{{ end }}
{{ define "content" }}
<section class="container list">
{{- range .Site.RegularPages -}}
{{- $categories := .Params.Categories -}}
{{- if eq $categories "A" -}}
<h3>{{ title $categories }}</h3>
<ul>
{{- .Render "li" -}}
</ul>
{{- end -}}
{{- if eq $categories "B" -}}
<h3>{{ title $categories }}</h3>
<ul>
{{- .Render "li" -}}
</ul>
{{- end -}}
{{- if eq $categories "C" -}}
<h3>{{ title $categories }}</h3>
<ul>
{{- .Render "li" -}}
</ul>
{{- end -}}
{{- end -}}
</section>
{{ end }}
I suspect that either .Site.RegularPages is not working (for which I tried .Page.Paginator which didn’t work neither) or I am missing some more code. Another idea?
In the above categories is a map. Do you assign more than one categories to a file?
EDIT
I do not use Hugo Extended. It appears that the theme author has not commited the theme’s resources and therefore I cannot look into testing the repo on my local machine. Perhaps someone else will have a further look.
At first, I did. Then I set one category per blog post (still didn’t work) and now after your question I deleted the map leaving only the string. This creates an error though
Failed to render pages: render of "page" failed: execute of template failed: template: posts/single.html:24:47: executing "content" at <partial "taxonomy/categories.html" .>: error calling partial: "C:\Website\themes\hugo-coder\layouts\partials\taxonomy\categories.html:3:27": execute of template failed: template: partials/taxonomy/categories.html:3:27: executing "partials/taxonomy/categories.html" at <.>: range can't iterate over Math
which is because of the following partial categories.html
git clone --single-branch -b hugo-forum-topic-31882 https://github.com/jmooring/hugo-testing hugo-forum-topic-31882
cd hugo-forum-topic-31882
hugo server
Then visit http://localhost:1313/blog/.
The important template code is in layouts/posts/list.html.
Error: Error building site: failed to render pages: render of "section" failed: "C:\Website\themes\hugo-coder\layouts\posts\list.html:21:11": execute of template failed: template: posts/list.html:21:11: executing "content" at <.Render>: Render is not a method but has arguments
Based on this (and thanks again @jmooring), there are some minor errors and design tweaks left:
All dates are wrong. The blog posts are all different with different dates but it gets displayed always the same date. Particularly irritating is that the 29 Nov 2020 isn’t the date of any of the blog posts displayed? I have no idea where that date comes from.
I want to position the categories A and B next to each other and the category C below A, i.e. there are always 2 categories per row, evenly spaced.
Right now, the date is below the (light-blue) blog post title. I would like to have the data on the left (i.e. in front) of the blog post title for each blog post. This would also reduce the excess space between the date and post title.
As of now, there is a superfluous Posts line next to each date. I would like to suppress or delete that.
Attempts/Ideas:
I have to somehow get the blog post date into the list.html file. Maybe .Site.Params.dateFormat? But where to put exactly?
To be honest, I have no idea how to do the spacing/grouping of categories.
I think the solution to this question is linked to the answer to question 1. As soon as I know how to include the blog post date, I can put it next to <a href="{{ .page.RelPermalink }}">{{ .page.Title }}</a><br> I suppose.
Finally, for the last question, I tried modifying {{ range where .Site.RegularPages.ByTitle "Type" "posts" }} but that crashed the site completely.
Thanks @alexandros, that solved the date problem. Considering your remark, do these other questions don’t have anything to do with Hugo and Hugo coding, i.e. don’t I have to change the list.html file similar as before? Is it completely independent from the list.html file?