How to add multiple lists in home page

Hi guys,
I need to add multiple post links in home page. GoHugo supports only one list in the home page. In my application, i need 3 different lists. Is there any way I can do this please ?
I created a github issue too. Please check my image there.


Any ideas are welcome.
Thanks.

I did so:

{{ range ((where .Site.RegularPages "Section" "in" (slice "archive" "books" "research")).GroupBy "Section").Reverse }}
                <h2>В раздел «{{ .Key }}»</h2>
                <ul class="li-main-article-list">
                    {{ range first 10 (where .Pages.ByLastmod.Reverse "Params.inlist" true) }}
                        {{ .Render "li-home" }}
                    {{ end }}
                </ul>
 {{ end }}

Result http://pokrovsky.newgod.su/

2 Likes

The algorithm depends on the sources from which you want to make lists. Lists can be made from sections, from taxonomies, from .Params in FM, etc.

1 Like

Hi, So how can i add pages according to your sections ? I mean .md pages ? Is there any specific property to add in those pages ? Can you give me some more explanation please.

By putting the markdown pages in folders under content. See:

… and generally if you search the documentation you will likely find some hints.

1 Like

I mean how you categories all ? Like “archive” “books” ,etc ?

That range statement that Mikhail cites is looking at all pages and seeing what section they are in. If you put a markdown file under a folder under content, it is in that section. Like:

content
   |
    --archive
                 |
                  file-a.md
                  file-b.md
1 Like

It means we can create different directories and then we can sort by the directory and get multiple lists according to those directories. Wow… that idea is simple.

{{ $n_posts := $.Param “recent_posts_number” | default 10 }}

                {{/* Range through the first $n_posts items of the section */}}
                {{ range (first $n_posts $section) }}
                    {{ $featured_image := .Params.featured_image }}
                    {{ if .Params.featured_image }}
                    {{/* Trimming the slash and adding absURL make sure the image works no matter where our site
                    lives */}}
                    {{ $featured_image := (trim $featured_image "/") | absURL }}
                    {{ end }}
                    <div class="col-md-4" style="text-align: center;background-color: #f3f3f3;">
                        <a href="{{.URL}}" class="db grow">
                            <img style="max-width: 100px;" src="{{ $featured_image }}" class="img"
                                 alt="image from {{ .Title }}">
                        </a>
                        <h6>{{ .Title }}</h6>
                        <hr>
                    </div>
                    <div class="col-md-1">

                    </div>
                    <!--<a href="{{.URL}}" class="ba b&#45;&#45;moon-gray bg-light-gray br2 color-inherit dib f7 hover-bg-moon-gray link mt2 ph2 pv1">{{$.Param "read_more_copy" | default "read more" }}</a>-->
                {{ end }}

This is my code. I have 2 directories in content sections. Posts and Posts1.
Can I take 2 lists from them ?

Yes, you should be able to using the technique Mikhail mentions.

Since you’re not linking a repo, I cannot see the details. For example, that template code (from a theme?) has $section set somewhere, but you don’t show that part.

Thanks for helping buddy.


This is the full code.
I can get all the posts in “posts” directory. I just need to duplicate same code to “posts1” directory and “extras” directory

Please check the comment I added above.
With my full index.html

What theme is it from?

You’re missing something at the top of the gist. It is pulling section names from the config.toml so look into that.

wait buddy. i’m uploading the project.

check this link and get the zip file

Ok, you’re using Ananke. Look into how the config.toml is supposed to be set up, before you do surgery. It appears to me that that snippet you pasted in the gist is supposed to support multiple sections, via a list in the config.

Where I can see the config.toml ? You mean in my own project ?

Oh buddy, just now got a way to add 2 lists… You are so helpful… :slight_smile:
Thanks a lot buddy… I’m new to hugo.
will be keep in touch with you… ok ?

no problem but I can’t guarantee availability. Just post here and someone will help. Best to post whatever source.