Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Fix entries on the same date being ignored by collection previous/next tags #8921

Merged

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Nov 3, 2023

This pull request fixes an issue where the {{ collection:previous }} and {{ collection:next }} tags would ignore other entries published on the same date.

For example, say you had the following entries:

  • 1st January: Article A
  • 5th February: Article B
  • 5th February: Article C
  • 7th March: Article D

When you visited the "Article C" entry, the {{ collection:previous }} tag would have returned "Article A" as the previous entry and "Article B" would have been ignored.

Similarly, when you visited the "Article B" entry, the {{ collection:next }} tag would have returned "Article D" as the next entry and "Article C" would have been ignored.

This PR fixes this issue by querying both entries before/after the current entry's date AND those on the same date where the title is greater/less than the current entry's title.

To make this work, ensure you have two sorts configured on the previous/next collection tag. The first being the date field and the second being the secondary column you want to order by, in my case that's the title.

{{ collection:previous in="articles" limit="1" sort="date:asc|title:asc" }}
    <a href="{{ url }}">
        {{ title }} ({{ date format="F j, Y" }})
    </a>
{{ /collection:previous }}

Fixes #1831.

@duncanmcclean duncanmcclean changed the title Fix entries on the same date being ignored by collection previous/next tags [4.x] Fix entries on the same date being ignored by collection previous/next tags Nov 3, 2023
src/Tags/Collection/Entries.php Outdated Show resolved Hide resolved
src/Tags/Collection/Entries.php Outdated Show resolved Hide resolved
@jasonvarga jasonvarga merged commit d125380 into 4.x Nov 3, 2023
35 checks passed
@jasonvarga jasonvarga deleted the fix/collection-previous-next-when-entries-share-the-same-date branch November 3, 2023 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collection:next/previous ignores other entries of the same day
2 participants