How do I make my frontpage show content from only one folder?

The current index.html code looks like this:

{{ define "main" -}}
<div class="posts">
{{ range .Site.RegularPages -}}
<article class="post">
  <h1 class="post-title">
    <a href="{{ .Permalink }}">{{ .Title }}</a>
  </h1>
  <time datetime="{{ .Date.Format "2006-01-02T15:04:05Z0700" }}" class="post-date">{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
  {{ .Summary }}
  {{ if .Truncated }}
  <div class="read-more-link">
    <a href="{{ .RelPermalink }}">Read More…</a>
  </div>
  {{ end }}
</article>
{{- end }}
</div>
{{- end }}

I tried changing part of the code index.html with only one of folders, called “posts”, with this code:

{{ range where .Site.Recent "/posts/" }}
  {{ .Render "li" }}
{{ end }}

I have tried my shitty google-fu, read documentation but there’s nothing mentioning how to include one folder of posts in my home page. How do I fix it?

I believe you want mainSections:

I Tried the following code in index.html and now there’s no html or css in the page. The home page is blank. What did I do wrong?

{{ define "main" -}}
<div class="posts">
{{ $pages := where site.RegularPages "posts" "in" site.Params.mainSections -}}
<article class="post">
  <h1 class="post-title">
    <a href="{{ .Permalink }}">{{ .Title }}</a>
  </h1>
  <time datetime="{{ .Date.Format "2006-01-02T15:04:05Z0700" }}" class="post-date">{{ .Date.Format "Mon, Jan 2, 2006" }}</time>
  {{ .Summary }}
  {{ if .Truncated }}
  <div class="read-more-link">
    <a href="{{ .RelPermalink }}">Read More…</a>
  </div>
  {{ end }}
</article>
{{- end }}
</div>

I also tried this as index.html in website/layouts/index.html and nothing happens. The behavior is different though: This code actually builds the website, but doesn’t apply the layout file.

I have a few ideas based on your snippet, but it would also help if we could see your source repository as per Requesting Help.

Before <article> you need

{{ range $pages }}

and after </div> you need
{{ end }}

Also do you have a layouts/_defaults/baseof.html defined? (If not, the define main won’t work).

And finally, I presume you have files under content/posts so that

picks up pages?

HTH.

I made a temporary repo here : GitHub - Tetizera/test-site

Take a look at

danielfdickinson/Tetizera-test-site (github.com)

particularly

Hope it makes sense. If not, please ask.

1 Like

Thank you for even coding this for me, but I still get posts from other folder “bipolar, about” on the home page. Not sure why and how to fix it.

Did you notice:

?

That’s in config.toml

One other question: what version of Hugo are you using?

I’m using version 87.0

Yeah, I can reproduce what you did in your code. My home page still have the copyright license on the home page.

Here is what I see:

Is what you get different? Or do you want something different?

Also note that where you had:

it should be:

{{ $pages := where site.RegularPages "Type" "posts" "in" site.Params.mainSections -}}

Oh, I’m an idiot! It was because the file on local was index.md when it’s supposed to be index.html

Thanks for all the help and patience!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.