[SOLVED] One page that list ALL posts


I want to create one page, that list all posts of website. Example: if I visit localhost:1313/all-posts/ this page shows all posts in the website.

1 Like


Create the following layout at layouts/section/all-posts.html

{{ define "main" }}
<ul class="all-posts">
{{range .Site.RegularPages}}
<li><a href="{{.Permalink}}">{{.Title}}</a></li>
{{ end }}

Note: The {{.Content}} in the above example will pull from the content file you have at content/all-posts/_index.md.

If you are talking about putting it in any other layout, you can always use .Site.Pages to grab all the pages (including _index.md in each section) or .Site.RegularPages, which grabs all pages except _index.md

1 Like

I guess what he asks for is better accomplished with:

  1. Template in /layouts/section/all-posts.html with {{range .Site.RegularPages }}
  2. A content page in /all-posts/_index.md
1 Like

@rdwatters this does not work properly.

So, I tried the @bep solution and this works fine.

I confess I don’t understand why I need to create a section instead create a simple .html in content with .Site.RegularPages.

Another question: when I put the posts inside content/posts, the URL looks like http://mydomain.com/posts/name-of-post/.
How can I make the URL looks like http://mydomain.com/name-of-post/ (without the /posts/) and maintain the posts inside the content/posts/ folder?

Guys, I really appreciated your help.

It’s the same thing that @bep wrote after I put my edit in it :wink:

A screenshot of your project will not help me much, but I’m glad it’s working now.

One thing to check is whether you are using block/base templates. If you’re not, then {{define "main"}} doesn’t mean anything. Also, judging by the highlighting in your screenshot, it looks like you put the all-posts.html in content/posts, but it needs to be in your layouts folder, which now helps me understand the following:

.Site.RegularPages is part of templating and not part of content.

By “name,” do you want the title or slug? In your site’s config.toml, the following will give you the URL you want:

  posts = "/:title"


  posts = "/:slug"

I advise :slug.

@rdwatters Great! posts = "/:filename" works like a charm!

Thanks to you and @bep for all help.
Yesterday I just finished to migrate all my website with more than 1650 posts and multiples authors to Hugo.
You can check it here: https://tableless.com.br/

Thx! \o/

1 Like

Where should the /all-posts/_index.md go exactly? Inside layouts dir? I can’t make it to work any way I try.

You are asking a question in a topic that was solved 5 years ago.

Please read the forum guidelines:

1 Like