Hi @jmooring. I got the setup you shared here to work. Thanks for that. However, I converted multipage = true to layout = "multipage" since I had already designed the layout and only incorporated the code in your single.html for posts.
A small issue occurs though when I include the list on homepage or a separate blog page. The list of pages appears with every post showing in the ranged list, with the paginated pages showing up as blank (see Screenshot by Lightshot). Is there a way to stop this from happening? Below is a sample of the code I am using to range through all posts
{{- $p := where site.RegularPages "Type" "post" }}
{{- $p1 := where (where site.Pages "Type" "post") "Layout" "multipage" }}
{{- $pages := union $p1 $p2 -}}
{{ range $pages.ByDate.Reverse | first 10 -}}
<-- code goes here -->
{{ end }}
Edit: I also added url: to the front matter of the index file and the other files, so the permalinks are consistent.
I should mention that these pages are part of nested sections, so it is not a whole section on its own. So, each nested section will have these multipage posts in future. If I donβt cascade the layout, the navigation buttons disappear on page 2 and subsequent pages.
Hereβs a modified example that uses the layout front matter value:
git clone --single-branch -b hugo-forum-topic-41042 https://github.com/jmooring/hugo-testing hugo-forum-topic-41042
cd hugo-forum-topic-41042
hugo server
This is definitely what I have been looking for all this time! Thanks for the time and effort youβve put into this Joe! Just a minor issue now relating to first that I will try to describe as I can. (I edited your code to sort by date and in reverse).
Assume the multipage post has two pages and its own _index.md` file.
Using your code above, adding first 5 to the range shows only the title of the multipage post. I assume the pages inside it are counted in the limit
When I change the limit to first 6 the next post (or page as it is know in Hugo), which is a regular page (not multipage), shows up in the sequence.
So, instead of having six posts, now there are only two posts appearing on the homepage/blog page.
Is there a way to make sure this does not happen? (I want to limit by 10 so only ten posts show up, including the multipage post).
One last question. How would .Paginate work with this code? It works flawlessly on the homepage, but I cannot replicate it on my blog page with $paginator.
Thanks for all this! I will have to redo some code here and there and edit existing posts to accommodate this solution (I had written a few multipage ones). Cheers!
Another small issue detected regarding Content Sections | Hugo. When using .Parent, the paginated pages inherit their own folderβs _index.md instead of the nested section. Do you have an idea on how to get around this? So, for example, in the <head>, for related posts in the nested section, and on JSON-LD schema, I use .Parent e.g to add the meta for article section or to limit the posts to a nested section. When on a paginated multi-page, the title in the multipage postβs _index_md appears with .Parent set instead of the title in the nested sectionβs _index.md.
This resolved two of the questions. The last one is concerning related pages. I am trying to adapt the code code you shared above to show related posts by nested section. For multipage posts, on the first page, posts from the same nested section as the multipage show up alright. But on the paginated pages, the related posts are the pages inside the multipage post with .Parent set. See my code below.
{{- $p := slice -}}
{{- range (where (where site.Pages "Type" "post") "Permalink" "ne" .Page.Permalink).ByDate -}}
{{- if or
(and .IsPage (not (eq .Layout "multipage" )))
(and .IsSection (eq .Layout "multipage" ))
-}}
{{- $p = $p | append . -}}
{{- end -}}
{{- end -}}
{{- $section := $p.ByDate.Reverse -}}
{{- $section := .Parent -}}
{{- $filteredPosts := $section.Pages -}}
{{- $relatedPosts := shuffle $filteredPosts | first 5 -}}
{{ range $relatedPosts }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{- end }}
{{- end }}
Neither. Letβs use the example of subsection-a. When visiting post-3 and its sub-pages, the related pages should be post-4 and any other page inside subsection-a. However, when pages 2-4 are open, then the related pages are the pages themselves inside post-3, rather than post-4 and any other pages in that subsection.