The Most recent post will only show at the bottom of the page

I am trying to add the most recent post to _index.md. When I put in the code on the home page it only shows it at the bottom of the page. If it does show it where I want to go then there will be dupilcation at the bottom of the page. The shortcode is

{{ range .Site.RegularPages.ByDate | first 5 }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{end}}

And in my _index.md I have

# Posts

{{< post >}}



# My and Other Projects

[Github](https://github.com/Luharion)



[đź”’Cyberscecurity blog](https://rebootcyber.xyz)

Can anyone help me out with this problem?

Edit: The repo: GitHub - Luharion/demo

The .ByDate method sorts in ascending order: the first one will have the earliest date.

Chain the .Reverse method to get a descending sort.

{{ range .Site.RegularPages.ByDate.Reverse | first 5 }}
  <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{end}}

Regarding the “duplication on the page”, it sounds like your list template already iterates over a page collection, and then you are adding another via your shortcode. But without seeing your repository I’m just guessing.

The theme I am using is GitHub - LukeSmithxyz/lugo: Luke's Hugo Theme

If you look at the default list page, you can see it’s already iterating over a page collection:

https://github.com/LukeSmithxyz/lugo/blob/master/layouts/_default/list.html#L7

I tried just copy and pasting the code and copy the whole file but when I do the pages looks like this

Hello World

Hello world

but the _index.md file look like this

# Hello World


{{< post >}}


# Hello world

The list still goes the bottom of the page.

Please post a link to the public repository for your project.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

This is the repo GitHub - Luharion/demo

We are not communicating very well.

You copied themes/lugo/layouts/_default/list.html into layouts/shortcodes/post.html.

Don’t do that.

Your shortcode should look something like:

<ul>
  {{ range .Site.RegularPages.ByDate.Reverse | first 5 }}
    <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
  {{end}}
</ul>

I copy the shortcode you send me and put it in layout/shortcodes/link.html. Then put
{{< link >}} in my _index.md. When I did that it still showed duplicates on the page


this is a test

    File

donate
about

    File


It shows duplicates because the template for list pages also ranges through pages. You are doing both on the same page.

If you want to change what is shown on your home page, create a template specifically for the home page.

mkdir layouts/_default
cp themes/lugo/layouts/_default/list.html layouts/_default/home.html

Then edit layouts/_default/home.html

Change this:

{{- range .Pages }}

to this:

{{- range .Site.RegularPages.ByDate.Reverse | first 5 }}

And do not include the shortcode in your home page markdown.

Thank you

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