Hi there,
I have a partial template that I'm using to create dynamic lists of pages based on tag, but I can't seem to get pagination working for my lists.
The code I have in my partial template looks like this (boiled down):
{% for post in tag.most_recent_published_pages limit:1 | paginate %}{{my post markup here}}
{% endfor %}
I have the limit set to 1 just for testing purposes.
Anyone have ideas on what needs to be different in order to get pagination up and running here?
Thanks,
Official response from Taylor Pineiro
Please see below!
Share this post
Showing 13 reactions
Sign in with
From the link it looks like you got it working, although not in reverse chronological order?
We want to display an archive of our past events so they aren’t just in the dustbin of history -
https://www.melbournefoe.org.au/past_events
We’re using
{% for event in page.calendar.events_past_all reversed %}
Which works as we would want but unpaginated, so worried it might impact on your servers and take a long time to load, especially as the archive will grow?
If this is not a big problem I’m happy to leave it as for now as its not going to be a popular page.
Otherwise
{% for event in page.calendar.events_past reverse %}
Shows something like 5 of the oldest events, also without pagination.
Thanks for tips!
NationBuilder employee
A ridiculously belated Thank You (10 months) to you. Yes, changing events_past_all to events_past did indeed cause the past posts to display. However, the “reversed” attribute I’d used to order the post excerpts in reverse chronological order (it defaults to chronological), no longer works. http://sa-350bayarea.nationbuilder.com/
This is not a big deal because we’ve moved our website (though not our supporter database or email communications) to WordPress. http://www.sunflower-alliance.org/
We did this to take advantage of the gentler learning curve for our team of volunteer editors. We preserve the legacy calendar and announcement posts on the NB website, which we provide links to in the Archive section in the sidebar of the new site.
Thanks for you help. If you know how I can reverse the chronological display on the calendar events, please let me know.
Thanks again,
Nick Despota
NationBuilder employee
You’re right – the events_past_all drop doesn’t limit output of pages automatically, which prevents pagination using the method we’ve talked about.
If you change events_past_all to events_past in both your forloop and pagination call and tick the box under the calendar settings to include events from all pages and not just that one, the pagination bar at the bottom will show up in place of that liquid error. This will also work if all the past events you want to call are housed under that calendar page – hopefully that combination lets you get where you need to go!
It would be a feature request to paginate the events_past_all drop, but I also think that part of the design of the “_all” suffix is to call them en masse, which limiting output would prevent, so let’s see if we can’t get it working with the above method before going down that route.
I have inserted this code after the forloop that shows all past events:
{{ page.calendar.events_past_all | paginate prev_label: “«” next_label: “»” }}
I get the following error in the location where the pagination links should appear: "Liquid error: undefined method `total_pages’ for #
Even if/when I do get the pagination links, I will face the issue of limiting the number of excerpts on this page to about 50 (there are 200+ past events that now appear on this page).
http://www.sunflower-alliance.org/calendar
BTW, we’ve set it up so upcoming events appear on our home page: http://www.sunflower-alliance.org/
Thanks
Nick
Thanks for reply. I do see the code for pagination in the template for my page and it matches what you sent. But the page, a list of excerpts still doesn’t paginate. Take a look: http://www.sunflower-alliance.org/calendar.
Here’s a section of the code (line 83-85 of the page template):
{% else %} <ul class=“event-wrap”> {% for event in page.calendar.events_upcoming %} <li>{% include “event” %}</li> {% endfor %} </ul> {{ page.calendar.events_upcoming | paginate prev_label: “«” next_label: “»” }} {% endif %} {% else %}
(The html entities, *«" etc. appear in the template as shown and I don’t expect have anything to do with the issue.)
Nick
NationBuilder employee
<ul class=“event-wrap”>
{% for event in page.calendar.events_upcoming }
<li>{ include “event” }</li>
{ endfor %}
</ul>
{{ page.calendar.events_upcoming | paginate prev_label: “«” next_label: “»” }}
We establish the forloop, and then paginate the object below. You can see this repeated numerous times in the stock Event page template for each of the different types (upcoming, upcoming_nearby, upcoming user-submitted).
{% for event in page.calendar.events_past_all limit:2 | paginate %}
(The 2 is for testing purposes. It will be more like 30 when I implement it.)
But the links for the next page are not showing at the bottom of my page. What code must I add to display the page links?
Thank you.