PRO: Pagination by twig – 1 feed, many pages

This page demonstrates how you can paginate data. All data comes in 1 feed (see here for data in several feeds)

Create a new JCI-Template for that:

{% set noonpage = 20 %}
{% set noofitems = ( days | length ) %}
{% if urlparam.no %}{% set selno = urlparam.no %}{% else %}{% set selno = 1 %}{% endif %}

number of data-items: {{ noofitems  }} at <a href="https://api.json-content-importer.com/extra/paginationdata.php" target="_blank">https://api.json-content-importer.com/extra/paginationdata.php</a><br>
{% set noofpages = (noofitems /noonpage) | round(0, 'ceil') %} show on {{noofpages}} pages:

{% set start = noonpage *(selno-1) %}
{% set end= start + noonpage %} 

{% for i in 1..noofpages %} 
{% if i==selno %} 
<b>this is page: </b> {{selno}} ({{start+1}} - {{end}})
{% else %} 
<a href=?no={{i}}>{{i}}</a>
{% endif %} 
{% endfor %}
<hr>
{% if noofitems ==0 %} No data-items found {% endif %} 
<ul>
{% for day in days | slice(start, noonpage) %} 
<li>
{% set currno = start + loop.index0+1 %} {{currno}}. {{day.FORENAMES}} {{day.SURNAME}}
</li>
{% endfor %} 
</ul>

Shortcode:

[[jsoncontentimporterpro nameoftemplate=pagination]]

Example in action:

number of data-items: 165 at http://api.json-content-importer.com/extra/paginationdata.php
show on 9 pages: 1 2 3 4 this is page: 5 (81 – 100) 6 7 8 9
  • 81. Stone Meyer
  • 82. Boyd Mills
  • 83. Warren Fox
  • 84. Rose Rice
  • 85. Moreno Schmidt
  • 86. Patel Ferguson
  • 87. Nichols Herrera
  • 88. Medina Ryan
  • 89. Fernandez Weaver
  • 90. Daniels Stephens
  • 91. Gardner Payne
  • 92. Kelley Dunn
  • 93. Pierce Arnold
  • 94. Tran Spencer
  • 95. Peters Hawkins
  • 96. Grant Hansen
  • 97. Castro Hoffman
  • 98. Hart Elliott
  • 99. Cunningham Knight
  • 100. Bradley Carroll