# of Recent Posts on Home Page Only, Defining Singular and Distinct Pages


I was wondering what’s the best way to go about these things.

Recent Posts on Home Page

All I want for the homepage is to have the 3 most recent posts, and the home page only.
Granted, starting out a new site won’t have more than 3 posts, but future-wise it will.

My first assumption was to make a partial to then use in layouts/_default/single.html:

<section class="section">
    <div class="container is-fluid has-text-centered">
        <h2 class="title">Recent Posts</h2>
        <div class="tile is-ancestor">
            <div class="tile is-vertical is-parent is-10">
                {{- range ( first 3 .Pages.ByDate ) }}
                  <!--- Do stuff in here --->
                {{ end }}

And the homepage content is in content/index.md as to not make use of a layouts/_default/list.html if it where _index.md instead. This partial would be called in layouts/_default/single.html in a

{{ if .IsHome }}
  {{ partial "home-recent-posts.html" }}
{{ end }}

Or something like that.

However, I think I’m making this a bit more complicated than needed. If I define an index.html in layouts/index.html or layouts/_default/index.html will that by default be my home page?

This somewhat leads into my second questions.

Singular and Distinct Pages

My site is going to have only these pages.

  • Home Page

  • About Page

  • Posts Page (list of pages with pagination)

  • Contact Page

These are all very distinct in how they are structured. As you can tell with the above, the home page can’t exactly be generically defined. The contact page will have a form in it and that’s basically it. About will be a bit more generic, but it’s not like the home page nor the contact page.

Is the way to go about this is to define an index.html file in the corresponding content/ folder, or can it be specfied in the layouts/ or themes/my_theme/layouts/ as about.html for example?

Yes, that will be a template that controls just the homepage.

The homepage by default is a list page. If you do not want to include a separate homepage template then in /layouts/_default/list.html you need to enter your above condition:

{{ if .IsHome }}
  {{ partial "home-recent-posts.html" }}
{{ end }}

The posts list page will also be controlled by the above template.

The about, contact and single posts pages will be defined by single.html that is the template for regular pages.