How to Show Most Recent Posts in Hugo
Published: 2024-02-04 | Updated: 2024-05-16This site’s home page features my most recent 5 posts. This the template logic that makes it happen.
<section class="recent-posts">
{{ range (where site.RegularPages "Type" "posts").ByDate.Reverse | first 5 }}
<div class="post">
<h2>
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
</h2>
<p class="date">
{{ .Date.Format "2006-01-02" }}
</p>
<div>
{{ .Description }}
</div>
</div>
{{end }}
</section>