Trying to add to the sidewide sidebar a list with “Latest posts” and another one with
the most popular tags (limited to 20 tags) but can’t achieve this for some reason.
For the list with the “Latest post” I use the code below and it works on the home page
but on the internal “post” pages it doesn’t render anything:
<h4>Latest</h4>
<ul>
{{ range first 5 .Data.Pages }}
{{if eq .Type "post" }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a>, {{ .Date.Format "02 Jan, 2006" }}</li>
{{ end }}
{{ end }}
</ul>
I have just one li.html in the /layout/default/ directory but I am not sure if this could be the problem?
About the “Tags” … I can’t render them at all even on the home page (but I have tags working on the “post” pages!).
Any hints will be appreciated.
The first case, does it fail when it renders each posts, post1.md, post2.md…? If so, those are rendered with single.html and Page object which is passed as the top level object so to access .Data.Pages, you should use .Site.Pages instead of that.
The second case, I think http://gohugo.io/taxonomies/ordering/ helps you. Using .Site.Taxonomies.ByCount and first together seem to satisfy your needs.
What version’s hugo do you use? If 0.12 stable release, try .Site.Recent instead of .Site.Pages. In my case, I confirmed it worked when I wrote the template code in layout/post/single.html. In your case, it would fall back to layout/_default/single.html and posts are rendered with it. If you still fail, could you tell me where you wrote the code and on which page (url) you had a problem?