A simple way to create subheads within lists

I’m using a version of the PaperMod theme for academic websites. I created a section for publications, and tried to create a list page that breaks publications into subhead sections by type (peer-reviewed publications, essays, etc.). However, the way I coded it the list page breaks after posts overflow into the second page and all the subheadings are retained even if the relevant posts were exhausted on page 1. I am attaching a link to my Github repository so you can see what I’m talking about, if you would be so kind as to help. The relevant “list” is under layouts>publications>“list.html” GitHub - claybdavis/hugo-academicwebsite

I apologize if this query isn’t thorough enough–I’m very much a beginner. I’d be happy to provide more information on request.

-c

I’m not sure what you mean by “second page” … there isn’t one.

This is what I did:

git clone --recurse-submodules https://github.com/claybdavis/hugo-academicwebsite
cd hugo-academicwebsite/

Then I made multiple copies of a publication with pr: true and multiple copies of a publication with pr: false. Then built your site with:

hugo server

The rendered list (http://localhost:1313/publications/) looks fine, so I’m not sure what the problem is.

thank you for your help with this and for reproducing my entire webpage by hand. How many copies of a publication did you make? Once you get to a certain number the entries move onto a second page that still has each heading despite the fact that the first heading will have no publications under it. I would like to have a smaller limit on the number of posts per page anyway, so if you lower that number in theory you would be able to see this glitch much more quickly. Regardless, is there a way to create a sectioned-out and subheaded list in a more elegant way than what I’ve done?

Have you added something to the template(s) that you haven’t pushed back to your repo?

Disregard. My test was invalid.

I just noticed that you are setting the url in front matter for every publication. For future reference, it’s a lot easier to use the permalinks configuration setting.

I’ll look at it again in a while.

OK, I still can’t figure out how you’re paginating… this template doesn’t contain any pagination code:
https://github.com/claybdavis/hugo-academicwebsite/blob/84ae3aefc2167fb3c193c69a48e84960499b7e08/layouts/publications/list.html

Hm, I might have removed the pagination at some point. sorry about that. this way of dividing a list does have the potential to cause that problem, though. do you know of any other way of doing what I’m describing?

Hard to say without seeing what you’re actually doing, but I suspect you want to group.

https://gohugo.io/templates/pagination/#list-paginator-pages

Search for “PageGroups”

Would that break the page into sections with subheadings? That’s all I want to do.

You are already doing that.

I cannot help you without access to a current (non-working) version of your project, and it would be helpful if I didn’t have to create a bunch of content to reproduce the problem you’re experience. Please help me to help you.

See Requesting Help.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.