This is giving me a surprisingly hard time. Has anyone tried to paginate entries by date, in this case, specifically by day; i.e.: First page loads today's posts, next page loads yesterday's, then the day before yesterday, etc.

I tried grouping items by date, as done in the archive page example, and then paginating the groups but it didn't work.

In this case I am using a combination of pagination + ajax to load more content when needed. However the needs of the project have changed, and paginating by number of items isn't the best approach. It'd be better to show content based on the date.


1 Answer 1


Instead of using pagination, you might try creating a custom route using tags for year/month/day. Those tags will be available as variables in the template that you can use to load that days entries and generate the nav for next/previous day, etc. Using ajax the uri won't be visible to the user anyway.

{% set postDate = year ~ '-' ~ month ~ '-' ~ day %}
{% set nextDate = postdate|date_modify('+1 day')) %}
{% set previousDate = postdate|date_modify('-1 day')) %}

{% set entries = craft.entries.postDate('and', '>= ' ~ postdate, '< ' ~ nextDate %}

{% for entry in entries %}
    {{ entry.title }}
{% endfor %}

<div class="pagination">
    <a href="{{ 'section/' ~ nextDate|date("Y/m/d") }}">next</a>
    <a href="{{ 'section/' ~ previousDate|date("Y/m/d") }} ">previous</a>

Not tested, but should be close. You'll need to modify the links to work with your ajax of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.