trepik
November 17, 2018, 8:58pm
1
On my homepage I’m usign pagination and I want to display posts from two section ordere by date. However, the order is kept within the sections but one older post from one section is above some younger posts from the other section. Here is the code I’m using:
{{ $paginator := .Paginate (where (where .Site.Pages "Section" "in" (slice "flash" "story") ) "IsPage" true) }}
{{ range $index, $element := .Paginator.Pages.ByDate.Reverse }}
zwbetz
November 18, 2018, 1:44am
2
On the 2nd line, try replacing .Paginator
with the $paginator
variable you declared (untested)
trepik
November 18, 2018, 8:42pm
3
I’ve already tried what you suggest, but no post are displayed then, the page stays empty.
zwbetz
November 19, 2018, 3:28pm
4
I would have to see your code to troubleshoot further.
But on my laptop, given this content structure:
├── content
│ ├── flash
│ │ ├── flash1.md
│ │ └── flash2.md
│ ├── nope
│ │ ├── nope1.md
│ │ └── nope2.md
│ └── story
│ ├── story1.md
│ └── story2.md
And this template code:
{{ $paginator := .Paginate (where (where .Site.Pages "Section" "in" (slice "flash" "story") ) "IsPage" true) }}
<ul>
{{- range $index, $element := $paginator.Pages.ByDate.Reverse }}
<li><a href="{{ .Permalink }}">{{ .Title }} -- {{ .Date }}</a></li>
{{- end }}
</ul>
I get this output:
<ul>
<li><a href="http://example.org/story/story2/">Story2 -- 2018-11-19 09:14:27 -0600 CST</a></li>
<li><a href="http://example.org/story/story1/">Story1 -- 2018-11-19 09:14:27 -0600 CST</a></li>
<li><a href="http://example.org/flash/flash2/">Flash2 -- 2018-11-19 09:14:27 -0600 CST</a></li>
<li><a href="http://example.org/flash/flash1/">Flash1 -- 2018-11-19 09:14:01 -0600 CST</a></li>
</ul>
trepik
November 20, 2018, 8:28pm
5
Thanks for trying to help realy appreaciate it.
Actually on the first page of the paginator the content is ordered by date correctly.
The issue is that on the second page of the paginatior is some younger content than the last one on the first page.
page1
flash5 (2018-11-20)
flash4 (2018-11-19)
story1 (2018-08-15)
page2
flash3 (2018-10-15)
flash2 (2018-10-03)
flash1 (2018-08-04)
zwbetz
November 20, 2018, 8:35pm
6
I see. So, you will need to share your code for me to troubleshoot further.
If you can’t do that, then create a sample repo that reproduces your issue, then share that.
zwbetz
November 20, 2018, 9:29pm
8
Okay I see the line you’re talking about now, but I’m not sure how to fix. Perhaps someone else more familiar with pagination can help you.
<h1 class="screen-reader-text">Posts</h1>
<div id="loop-container" class="loop-container">
{{ $paginator := .Paginate (where (where .Site.Pages "Section" "in" (slice "flash" "story") ) "IsPage" true) }}
{{ range $index, $element := .Paginator.Pages.ByDate.Reverse }}
{{ $scratch := newScratch }}
{{ if .Site.Params.writers }}
{{ $scratch.Set "writer" (index .Site.Params.writers (lower .Params.writer) | default dict) }}
{{ else }}
{{ $scratch.Set "writer" .Site.Params.social | default dict }}
{{ end }}
{{ $writer := $scratch.Get "writer" }}
{{ if and (isset .Params "image") .Params.image }}
{{ if eq (mod $index 2) 0 }}
<div class="post type-post status-publish format-standard has-post-thumbnail hentry category-design tag-memories tag-normal-post tag-standard-2 excerpt zoom full-without-featured odd excerpt">
trepik
November 20, 2018, 9:36pm
9
Actually I figured it out… by adding .ByDate.Reverse
in the the first line (L4), where the paginator is created … thanks anyway for your help.