61
votes
Accepted
How to link to previous/next entries in a section?
You are probably not using this within a craft.entries loop. Position it inside a loop or set custom parameters for your prev and next elements:
{# Set parameters for prev/next elements list #}
{% ...
20
votes
How to link to previous/next entries in a section?
You can set the prev.url at the top of the template, for example:
{% set criteria = {section: 'blog', order: 'postDate'} %}
{% set prev = entry.getPrev(criteria) %}
Add a link if prev is available:
...
15
votes
Accepted
How to paginate search results?
{{ paginate.nextUrl }}?q={{ query }} did the trick with this setup.
12
votes
Accepted
Any examples of numeric pagination?
Sure, http://buildwithcraft.com/docs/templating/paginate
{% paginate craft.entries.section('blog').limit(10) as entries %}
<a href="{{ paginate.firstUrl }}">First Page</a>
{% if ...
10
votes
Accepted
Troubleshooting paginated content cached globally
I ran into this today. I thought craft.request.path used to include the pagination page number but it doesn't appear to anymore. Maybe it was always like this though.
Regardless, this is how I'm now ...
9
votes
How do i setup ajax paging for entries
Hey So here is what i came up with, curious if anyone has a more streamlined approach.
https://gist.github.com/keithmancuso/17619fc405a621b4a11e
{% if craft.request.isAjax %}
{% set layout = "...
9
votes
Accepted
Check if paginate
The paginate.totalPages variable will give you the total number of pages that are generated by the paginate tag. So you can wrap your display of pages around a conditional that checks to see if this ...
9
votes
Using pagination on a page with url with query string data
In most Craft projects I do I'll create a pagination include file so anything I need that requires pagination, I can just include that and I get the same pagination pattern anywhere within my site ...
7
votes
Accepted
Sensible way to have different number of entries on page one of pagination?
There's an offset parameter that allows you to skip the first entries from your ElementCriteriaModel.
You would set up two nearly identical ElementCriteriaModels, one exclusivly for your featured ...
7
votes
Accepted
How can I show next/previous paging that's limited by specific criteria?
You can only pass an object or an ElementCriteriaModel (what you get when you type 'craft.entries') into getNext() and getPrev().
Calling find() on an ElementCriteriaModel, as I'm doing in my code, ...
6
votes
Accepted
Back to paginated page
The easiest way would be to check craft.request.urlReferrer and see if they just came from the entry index page. If so, provide a link to send them back.
{% set referrer = craft.request.urlReferrer %}...
6
votes
Accepted
Paginate an array with multiple filters
Try using this (completely untested):
{% if paginate.prevUrl %}
<a href="{{ paginate.prevUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Previous Page</a>
{% endif %}
{% if ...
6
votes
How do i setup ajax paging for entries
Thanks to Kieth for posting an ajax solution. I just wanted to expand on it a little bit to figure out when we are at the end of the entries etc so we can hide loading more buttons etc. Here is what I ...
6
votes
Accepted
Exclude category from channel entries (with pagination)
The without filter converts your ElementCriteriaModel into an array of entry models (the same as find() does). But that array won't work with paginate, as explained in the docs:
This parameter ...
6
votes
Accepted
Getting the last X number of pages in pagination
As I already wrote in my comment 3 days ago something like this should work
{% paginate craft.entries.section('mySection').limit(10) as pageInfo, pageEntries %}
{% for page, url in pageInfo....
5
votes
Accepted
Search Results Pagination with multiple form fields
To get this working, you will need to find a way to continue passing all of your form’s values to each of the additional pages.
There are a few ways you could do that, but the easiest and best option ...
5
votes
Accepted
Paginate Entries With The Same Tag
You can limit the prev/next links to only show entries with the same tags using the relatedTo param:
{% set params = {
section: 'databytes',
order: 'title',
relatedTo: { targetElement: ...
5
votes
Accepted
Use different template for paginated entries
I don't know if there's a route way to handle this, but you could do a conditional on the craft.request method getPageNum() like so:
{% if craft.request.getPageNum == 1 %}
<!-- Header for the ...
5
votes
Accepted
How do I create pagination links for my entry index page?
You have your {% for %} and {% paginate %} tags in the reverse order. You need to wrap the loop and the pagination URLs with the {% paginate %} tag pair:
{% paginate craft.entries.section('houseRules'...
5
votes
Accepted
Modify ElementCriteria and use it for paginate
You can only modify a craft.entries criteria model with a field (→ Add custom element criteria attribute without a field type?). So what you have to do is to create a new custom field type with your ...
5
votes
Accepted
Paginate entries with offset / limit when templating
You could use Twig's Slice function.
{% set firstTwo = paginatedEntries|slice(0,2) %}
{% set lastFour = paginatedEntries|slice(2,4) %}
Then loop over firstTwo for your first items.
{% for entry ...
5
votes
{% paginate %} Tag issue, no prevUrl / nextUrl Data
You need to set a limit on your element query, so Craft knows how many entries you want per page:
{% paginate craft.entries.section('newsBlog').limit(1) as pageInfo, pageEntries %}
If you don't set ...
5
votes
Accepted
Pagination and Entry Model on Homepage
project.images is an array because you are eager-loading the images.
Since you’re only loading one project entry, you’re not actually gaining anything by eager-loading the images (or category), ...
4
votes
How do i setup ajax paging for entries
I would use Craft's built in paginate tag. You just add the page number (p2, p3, p4, etc.) to the end of the url in your ajax call and output the template like this:
{% paginate craft.entries.section(...
4
votes
Accepted
What's the best way to paginate through entries from an entries field type?
To do this, you would need to use getPrev() and getNext() on the related entries’ template.
The trick is telling getPrev() and getNext() to use the order you defined in the source entry’s Entries ...
4
votes
Back to paginated page
This is not something built into Craft, but you could accomplish this with a plugin. You could have it run during your plugin's init function. On each page load, it would take the current page and ...
4
votes
Accepted
Paginate Entries by Day
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 ...
4
votes
Any examples of numeric pagination?
Good starting point: https://craftcms.com/docs/templating/paginate
If you also want display '...' instead of the whole list of page numbers, you can do something like this:
{% if pageInfo.totalPages ...
4
votes
Get value from dropdown and use in Twig
Twig (and all php) is processed server-side before javascript even gets initiated. And once the page renders in the browser there no way to interact directly with twig. The only two options that you ...
4
votes
Exclude category from channel entries (with pagination)
The probably more elegant way to handle this is to not use the without filter at all and simply
list the categories you want to exclude prefixed with not.
{% set categories = craft.categories({
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pagination × 120entries × 22
templating × 12
craft3 × 9
categories × 7
search × 7
ajax × 7
elementcriteriamodel × 6
cache × 5
group × 5
relations × 4
url × 4
array × 4
previous-next × 4
datetime × 3
routes × 3
forloop × 3
query × 3
relatedto × 3
loop × 3
merge × 3
limit × 3
plugin-development × 2
matrix × 2
filter × 2