Displaying the list of posts by section

Hi, evry one. I want to display, in the sidebar, the posts from the current section, which would get such a structure of outputs: where all posts are linked to each other, that each post would be linked to another, any post, the current section
Now I do it this way:

{{ range first 5 where .Site.Sections “Section” .Section }}

The problem is that on all pages the output is the same, plus the output includes the name of the section and the name of the current open post, which I would also like to avoid.

Try,

{{ range where .Site.Pages "Section" .Page.Section | first 5 }}

You can also add a sort order

{{ range where .Site.Pages.ByLastmod "Section" .Page.Section | first 5 }}

You can find more information at:

and

1 Like

Thanks for the answer and materials! But the result is the same. Let me explain by example what the structure should be:
I have 10 articles in a section. For example, post1, post2, post3, etc. In your or my way, in the sidebar output of posts is as follows:

  • post10
  • post9
  • post8
  • post7
  • post6

And when you switch to, for example, post8, the output will remain the same:

  • post10
  • post9
  • post8
  • post7
  • post6

That is, links to the first 5 posts do not get into the sidebar.
For SEO optimization, it will be necessary that, for example, when going to post8, the post’s output will be:

  • post7
  • post9
  • post3
  • post1
  • post5

While going to post3, the output will be:

  • post4
  • post2
  • post10
  • post7
  • post6

Etc. The order in which the posts are displayed is irrelevant.

It seems to me that what you want can be achieved with:

Thanks for your help!

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