Hello
In my theme, I want to create a second add-on page with a feed of posts, in which posts will be sorted by update date, or any other parameter. Can this be done somehow?
Hello
In my theme, I want to create a second add-on page with a feed of posts, in which posts will be sorted by update date, or any other parameter. Can this be done somehow?
There can only be one home page at the root of your site, unless you made the site dynamic (i.e. non-Hugo) and changed it depending on certain conditions, like the presence of particular data in a cookie.
You can add other pages that will give different βviewsβ on your content. Add a page called date.md and add layout: "datesort"
to the frontmatter (if you are using YAML). Then create a datesort.html layout template in the layout
folder that sorts according to how you want it to be sorted. Thatβs the hard part.
Then add a link from your home page to this page.
Hello
Thanks for the advice, but I didnβt fully understand what needs to be done ((
I created a folder called βbetterβ in the βcontentβ folder and put index.md in it. It indicated: layout: βbetterβ.
In the template itself, I added a better folder to the layouts folder and index.html to it.
But nothing worked. Yes, the page / better appeared, but there is a wrong template
The template under layouts/better/index.html
is meant for a Section list page.
Yet you have /content/better/index.md
which is a Single Page controlled by /layouts/better/single.html
You need to either rename the template to single.html
or if /better/
is meant to list more content files you need to change the index.md
to _index.md
so that you get a published Section and not a Single Page.
See the template lookup order for Page Kinds:
I renamed index.md to _index.md and in the end it didnβt help. Yes, the template has changed. Layouts / _default / section.html is now used instead of single, but not layouts / better / index.html
We cannot know what is your setup without seeing the full context.
See the Requesting Help guidelines and provide a minimal repo that reproduces your issue.
However I am terribly busy at the moment and Iβve no time for support in this forum.
Perhaps someone else can look into it, if you provide a repo.
Perhaps I did not describe my problem correctly.
I do not need a separate topic for the section, these are the tips that you seem to be giving me. I need to create two pages similar to /layouts/index.html with different sorting approaches.
Thus, I want to get the main page mydomain.com/index.html and an alternative main page, for example mydomain.com/better, which will have the same posts as on the main page. But on the main page they will be sorted by creation date, and on / better by modified date.
That is, if you cannot sort content on the fly due to the limitations of static sites, I would like to provide users with two or more alternative sorts in advance. On the main page by the date it was added, and on the alternative by the date it was updated
Content structure:
content
βββ better
β βββ _index.md
βββ post
β βββ post-1.md
β βββ post-2.md
β βββ post-3.md
βββ _index.md
content/better/_index.md
+++
title = "Better"
date = 2021-03-04T17:02:42-08:00
draft = false
type = "post"
layout = "posts-by-lastmod"
+++
Template structure:
layouts
βββ _default
β βββ baseof.html
β βββ list.html
β βββ single.html
βββ post
β βββ posts-by-lastmod.html
βββ index.html
layouts/post/posts-by-lastmod.html
{{ define "main" }}
{{ .Content }}
{{ range (where .Site.RegularPages "Type" "post").ByLastmod.Reverse }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ end }}
layouts/index.html
{{ define "main" }}
{{ .Content }}
{{ range (where .Site.RegularPages "Type" "post").ByDate.Reverse }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
{{ end }}
config.toml (see https://gohugo.io/variables/git/#lastmod)
enableGitInfo = true
@jmooringβs answer is great, and I think it should have solved your problem.
I add a few links that I think might be useful to you, as follows:
Here are some examples of what I have done on my own site
layouts/site-tree.html
contents/site-tree.md
This is a great answer and it works for me.
But I would like to clarify if it is possible to somehow embed it in the template so that template users do not need to create an md file.
I donβt understand your question.
@jmoorings not the OP but jmoorings answer was super helpful. Was playing around with something similar on a site Iβm testing. Thanks for sharing!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.