I woul like to be able to put independent posts and articles under /hobbies/photo, hobbies/music etc.
with urls like hobbies/photo/post1 /sports/ski/post1 etc.
Hobbies and sports are sections.
I think of photo, music, etc as subsections.
Or should I think of them as categories?
I would like to have independent taxonomies (tags) for hobbies and sports (may be even for some of the subsections).
I am using ananke theme for now (whether the used themes matters).
I have created dirs under content for each section and subsection a _index.md file under it copied from the content/_index.md.
When I navigate to /hobbies/photo/ I can see the posts under that subsection.
When I navigate to /hobbies/ I only see posts that are directly under /hobbies/
I would like to see posts that are in subsections, like /hobbies/photo or /hobbies/music.
How can I do that?
Can you do that without changing the theme layouts, just using _index.md files?
I would like to have independent tags for hobbies and sports too.
How can you create tags to use in a sections and its subsections?
And how may you limit the tags used, in general the terms used in a taxonomy?
I have read all of that and here in the forum.
But I did not understand how to get posts organized that way.
All the examples I have found suppose younare creating a blog with posts under post section znd in other sections you have pages other type of content.
But i want to have separate sections with post in them ando other type of content.
A front page that shows recent posts from any of the sections and when you land to one of the sections like /hobbies/ only posts from that section and its descendents are shown.
Same with subsection like /hobbies/music/
I have not found an example similar to that in the whole documentation.
You’ll probably get something close to what you want by just using the exact structure you described as the directory structure for the /content dir. Hugo will use it to build your site.
The problem would be that your theme doesn’t have a “hobbies” template, so you’d need to change some configurations so that the template you want gets applied. The links provided by @alexandros will help you with that.
I can use sections and subsections.
It works quite well.
But I have a couple of problems:
when I navigate to /hobbies/ I get a list of the posts in it correctly.
But the page is not displayed the same way as the built in /posts is.
I have been reading about how hugo organizes themes.
There is a layouts\section so as both, posts and hobbies, are sections, they both should use the layouts defined there.
But they render differently.
I could not find the way to format items in my section the same way as post section (by the way, what a mess I have with plurals and singulars. Shouldn’t posts section be in plural posts and not post?).
The other problem is getting the section to list posts and other content in its subsections.
But I think this is bound to the way a theme is design.
Academic uses .Data.Pages variable in the section templates. So, it only gets the items in the current section (from the
To get descendents I should use .Section.RegularPagesDescendent.
So I have to override section templates.
Am I right?
I will try, but it seems that the organization I would like to get is achievable.
Yes. Overrides go under the /layouts/ folder under the route of your project. You need to place the new template under the exact replicated PATH of the template that resides under /themes/theme-name/
That is a choice that you can make on your own.
By the way Hugo has no concept of the plural form i.e. posts and post are two different content types. A template for posts will not control content residing under /content/post/ by default.
Thank you. I will try to modify the templates and see if I can get what I am looking for.
Of couse I meant RegularPagesRecursive.
What is the difference between .Data.Pages and .Pages?
It seems that .Data.Pages references only the same page type of the page that is using the template.
But there is no .Data.PagesRecursive.
Academic seems to be using .Data.Pages because it uses the same template for multitude of pages.
.RegularPages won’t retrieve pages of other types than posts and similar pages. I am not sure if it is going to work well (changing section\posts.html instead of making one for eache section).
Will see.
I could configure the section\posts.html to list posts in subsections.
I made a front matter variable (listRecursive) to control how the list should be generate:
none (or not set) it works as it was, it list and paginates all kind on pages in the section only.
mixed: it lists and paginates only regular pages in the sections and its descendents.
separate: it llists first regular pages in the current section and then lists subsecions (directly under the current section) and the regular pages inside that sections.
simple: it lists first regular pages in the current section and then all pages in descendent subsections.
none, mixed and separate seem to work OK.
But I am having troubles with the simple mode of listing.
Heres is the code (simple listing is near the end):
{{- define "main" -}}
{{ partial "page_header.html" . }}
<div class="universal-wrapper">
{{ with .Content }}
<div class="article-style">{{ . }}</div>
{{ end }}
{{ $listRecursive := ($.Params.listRecursive | default "none") }}
{{ $paginator := "" }}
{{if eq $listRecursive "mixed" }}
<h3> MIXED</h3>
{{ $paginator = .Paginate .RegularPagesRecursive }}
{{ else if eq $listRecursive "none" }}
{{ $paginator = .Paginate .Data.Pages }}
{{ else }}
<h3> SEPARATE OR SIMPLE </h3>
{{ $paginator = .Paginate .RegularPages }}
{{ end }}
{{ range $paginator.Pages }}
{{ if eq $.Params.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $.Params.view 3 }}
{{ partial "li_card" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ end }}
{{ partial "pagination" . }}
{{ if eq $listRecursive "simple"}}
<h3> SIMPLE </h3>
<h2>Posts in subsections</h2>
<div class= "universal-wrapper">
{{ $subsectionList := where .RegularPagesRecursive "CurrentSection.Permalink" "<>" .CurrentSection.Permalink }}
{{ $paginator := .Paginate $subsectionList }}
{{ range $paginator.Pages }}
{{ .CurrentSection }}
{{ if eq $.Params.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $.Params.view 3 }}
{{ partial "li_card" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ end }}
{{ partial "pagination" . }}
</div>
{{ else if eq $listRecursive "separate"}}
<h3> SEPARATE </h3>
{{ range .Sections }}
<div class= "universal-wrapper">
<h2> {{- .Title -}} </h2>
{{ $paginator := .Paginate .RegularPages }}
{{ range $paginator.Pages }}
{{ if eq $.Params.view 1 }}
{{ partial "li_list" . }}
{{ else if eq $.Params.view 3 }}
{{ partial "li_card" . }}
{{ else }}
{{ partial "li_compact" . }}
{{ end }}
{{ end }}
{{ partial "pagination" . }}
</div>
{{ end }}
{{ end }}
</div>
{{- end -}}
The problem is that even if I filter the pages in $subsectionList to get only the pages that are descendent from the current setion, excluding pages in this section that have been listed at the top, when I use .Paginate it only shows the page that I have in the current section.
$subsectionList has the correct pages (I have tested it subsituting the paginator by this list).
But when I use .Paginate to get that list paginated, I only get the page in the current section (that should not be shown as it is excluded from the list to show).
It seems that I don’t undersand well how .Paginate works, it seems that it operates in the current section.
How should I Paginate a collection or pages that I have in a variable?
Does Paginator work only in a list with the .Pages collection of the list and not with .RegularPagesRecursive?
I haven’t worked with .Paginator much, sorry I can’t be of much help.
But you will probably have better chances of people answering if you open another topic with a specific question, since the original one has been answered. As pointed out before by @alexandros, be sure to read Requesting for Help.
OK, you are right.
May be its better to make a specific question about paginator, as the original question is solved and the problem seems to be with Paginator.
I will try to make the question more concise about that (it is not easy to me to express ideas in english).
Thank you very much.
I have to say that it has impressed me how easy can be to edit a layout.
At first I got a bit threatened by all tath {{}} code.
But once you undertand a bit how it works and having the layouts from the base theme, it does not seem all that difficult.
Of course I have a lot to learn about Hugo but I am getting in love with it.