Hi - newbie alert - I’m creating a new theme for my weblog.
The home page has only the 3 most recent posts. Each one links to the post itself, i.e. a “single.html” template. Now I’d like to include a longer list of recent posts as sidebar - how is this done in Hugo? I guess I’m a bit confused w.r.t. the single / list template split: it’s a single page in that it shows one post in full, but it needs to include a list of the last N posts as well.
Apologies if this is a FAQ - I haven’t found an answer or matching example so far.
-jcw
Update - using “.Site.Pages” iso “.Data.Pages” with “where” filtering got me going (as mentioned here). Not sure it’s the “proper” way to do this, but it works.
But alas no code sample to see how they were applied…
update for all those spending their afternoon tyring to create a list of recent posts on a single piece of content… this worked for me.
{{ range where .Site.Pages "Section" "blog" }}
<li><a href="{{ .Permalink }}">{{ .Title }}</a><br /><span class="date">{{ .Date.Format "Mon, Jan 2, 2006" }}</span></li>
{{ end }}
Can someone explain to me why this code below only worked on a list view and return only blank on single view?
{{ range .Data.Pages.ByDate }}
<li><a href="{{ .Permalink }}">{{ .Title }}</a><br /><span class="date">{{ .Date.Format "Mon, Jan 2, 2006" }}</span></li>
{{ end }}
Clearly .Site.Pages is being filtered… I guess I still don’t understand the difference between .Site.Pages and .Data.Pages… and why .Data.Pages doesn’t work on single views…