Auto Title For Different Subsection

Dear All

I have 3 section (blog, poem, quote) with several subsection inside poem section folder like this -> https://angora.me/blog/

/blog/ (blog posts with _index.md here) 

/poem/ (only _index.md here) 
|_ /2010/ (poem 2010 posts with _index.md here) 
|_ /2011/ (poem 2011 posts with _index.md here) 
|_ /2012/ (poem 2012 posts with _index.md here) 
|_ /and more... /

/quote/ (quote posts with _index.md here) 

On the single.html I added this part ->

<header class="entry">
<a href="{{ .Permalink }}">
<div class="center">
<h2>{{ .Section | humanize }}</h2>
</div>
</a>
</header>

It work for single post inside blog and quote folder. But for single poem inside 2010, 2011, 2012, etc, the header still display parent section (Poem), not subsection (Poem 2010, Poem 2011, Poem 2012, etc).

Here is the example ->

Any suggestion to fix? Also, how to make every header linking to every section and subsection? Because if I use <a href="{{ .Permalink }}"> (like my code above), it always linked to the current page?

Regards

Hi,

From the docs: .Section returns

the first path element in the directory, for example, /blog/funny/mypost/ => blog .

Try .Parent instead.

Hugo has an example breadcrumb navigation: https://gohugo.io/content-management/sections/#example-breadcrumb-navigation

Tried {{ .Parent }} but it returns to filepath, not parent.

.Parent would return the Page; use .Parent.Title if you want to use the title of the parent page.

2 Likes

Yes, finally it works with {{ .Parent.Title }} and {{ .Parent.URL }}

Thanks, @pointyfar :beer: