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 ...
6
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 ...
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
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
Check paginated currentPage before setting the paginate tag
Ok, so after discovering the getPageNum request, I found the following solution:
{% set pageNumber = craft.request.getPageNum %}
{% set firstPageLimit = 5 %}
{% set defaultLimit = 8 %}
{% set limit =...
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
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
Accepted
Using prevSiblingOf and nextSiblingOf
Those parameters are only meant to be used on entries within Structure sections. (Just updated the docs to make that more clear.)
If you want to get the next/previous entries within a Channel section,...
4
votes
Accepted
Reverse count with paginated entries?
You already pass the array keys into the loop as a variable pageInfo. There's a couple of properties you can access from it, see the Craft docs:
Templating Reference → {% paginate %}
Of interest for ...
4
votes
Accepted
Paginate entries when I do not have a criteria model?
This is in no means an elegant solution, and can almost certainly be improved. But it did its job just fine.
{% set veterinarians = craft.entries({
section: 'veterinarians',
order: '...
4
votes
Accepted
Excluding a single Entry ID of an Entry Type from craft.entries
You'd have to add a conditional and render the featured entry on the first paginated page only. You can access that info from the pageInfo variable.
Another thing I'd do is to remove the featured ...
4
votes
Accepted
Including Zii in Craft CMS
Craft 2.x ships with a subset of the Yii framework files with things like zii and Yii widgets stripped out.
If you wanted to utilize them, you'd have to create a Craft plugin and manually include the ...
4
votes
Accepted
provide a 'back' or 'cancel' or 'close' button to return to whatever page that particular template was accessed from
You could use the Cookies plugin to store the last visited URL before the user hits one of the "step" templates, i.e. by putting something like the following in every template where the links to the "...
4
votes
Pagination with randomly ordered entries
Why is this happening?
Why am I seeing duplicates?
When the database is told to sort by random, the entire list of entries is being sorted into a random order before your required page of items is ...
4
votes
Order entries by a category field alphabetically then paginate
In order to sort your entries by a related field you need to join the relations and the content table and sort your entries by the column you want. The it doesn't change the behavior of your paginate
...
3
votes
Accepted
Eager-load and pagination
with is just another query param, like limit or whatever parameters you’re defining in entryParams.
The {% paginate %} tag requires that you pass in an ElementCriteriaModel, but as soon as you call ...
3
votes
Accepted
Only fetch structure entries that are first level or sub level that don't have a parent
You can use the hasDescendants() method to filter out any parent entry with children. You have to use an ElementCriteriaModel with .getPrev() and .getNext().
{% set entries = craft.entries.section( '...
3
votes
Accepted
Combing an If Statement with Pagination
To get the pagination to work as expected, you need to incorporate the if into your craft.entries query. There may be a more elegant solution to do this, but looking at the database, the selected ...
3
votes
How to link to previous/next entries in a section?
For navigating siblings in a structure there's a shortcut:
{% if entry.prevSibling %}<a href="{{ entry.prevSibling.url }}">Previous</a>{% endif %}
{% if entry.nextSibling %}<a ...
3
votes
Showing pagination for a date range of entries
It's difficult to give specific code help without seeing some input/output examples, but here's a go-by:
You can say that an event occurs during a date range if:
The event begins before the date ...
3
votes
Accepted
Use paginate info in another block
As of Craft 2.5.2750, you can leave off the {% endpaginate %} tag, then move your {% paginate %} tag up outside of the blocks in the posts/index.twig template, and your pageInfo variable should be ...
3
votes
Pagination base URL - any way to have pagination links go to URLs other than current one?
Since version 3.1.28, you can set base URL of pagination links, like this:
{% paginate query as pageInfo, pageEntries %}
{% do pageInfo.setBasePath('new_url') %}
3
votes
Accepted
Pagination base URL - any way to have pagination links go to URLs other than current one?
Not tested, but I would assume that you could simply get the total entries, divide by the pagination limit and then generate your dynamic nav using a range loop.
{% set totalEntries = craft.entries....
3
votes
Accepted
Check which pagination page to display code outside of pagination loop
UPDATED/EDIT ANSWER:
If you only want to show the entries on the first page you should make an if statement to check if you are on the first page for your Featured Items by requesting the page number....
3
votes
provide a 'back' or 'cancel' or 'close' button to return to whatever page that particular template was accessed from
If you need to set a correct link on the cancel buttons than using browser history is the easiest way.
{% if entry is defined %}
// Going to STEP2
<button onclick="window.history.go(-1); ...
3
votes
Accepted
Using pagination on a page with url with query string data
The huge advantage of craft over other CMS is the high flexibility and the ability to customize many things. Thus Craft won't provide non changeable <a> tags but links you can change like you ...
3
votes
Cache and Pagination not working
Based on the code you posted on pastebin, it seems like the problem is that you have your pagination outside of the cache tags (assuming this was the case when you had caching implemented). And, I'm ...
3
votes
Accepted
Graphql total results / pageinfo when searching with pagination
Try entryCount. You can also add arguments to this, such as section: entryCount(section:"news"), for example.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pagination × 124entries × 23
templating × 12
craft3 × 9
categories × 7
search × 7
ajax × 7
elementcriteriamodel × 6
cache × 5
group × 5
relations × 4
url × 4
routes × 4
query × 4
array × 4
merge × 4
previous-next × 4
datetime × 3
forloop × 3
relatedto × 3
loop × 3
channels × 3
limit × 3
plugin-development × 2
matrix × 2