Module for generating pagination markup automatically for paginated WireArray types.
// Get an instance of MarkupPagerNav
$pager = $modules->get('MarkupPagerNav');
This module can create pagination for a PageArray
or any other kind of PaginatedArray
type.Below is an example of creating pagination for a PageArray returned from $pages->find()
.
// $items can be PageArray or any other kind of PaginatedArray type
$items = $pages->find("id>0, limit=10"); // replace id>0 with your selector
if($items->count()) {
$pager = $modules->get("MarkupPagerNav");
echo "<ul>" . $items->each("<li>{title}</li>") . "</ul>";
echo $pager->render($items); // render the pagination navigation
} else {
echo "<p>Sorry there were no items found</p>";
}
Here’s a shortcut alternative that you can use for PageArray types (thanks to the It’s common to specify different markup and/or classes specific to the need when rendering
pagination. This is done by providing an The full list of options can be seen below. Please note that most options are set automatically since this module can
determine most of the needed information directly from the WireArray that it’s given. As a result, it’s often
not necessary to change any of the default options unless you want to change the markup and/or classes used in output. Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the In addition to the methods and properties above, MarkupMarkupPageArray
module).
Note that in this case, it’s not necessary to load the Markup$items = $pages->find("id>0, limit=10"); // replace id>0 with your selector
if($items->count()) {
echo "<ul>" . $items->each("<li>{title}</li>") . "</ul>";
echo $items->renderPager(); // render the pagination navigation
} else {
echo "<p>Sorry there were no items found</p>";
}
$options
array to the Markup
call.
In the example below, we'll specify Uikit markup rather then the default markup: // Change options for Uikit "uk-pagination" navigation
$options = array(
'numPageLinks' => 5,
'listClass' => 'uk-pagination',
'linkMarkup' => "<a href='{url}'>{out}</a>",
'currentItemClass' => 'uk-active',
'separatorItemLabel' => '<span>…</span>',
'separatorItemClass' => 'uk-disabled',
'currentLinkMarkup' => "<span>{out}</span>"
'nextItemLabel' => '<i class="uk-icon-angle-double-right"></i>',
'previousItemLabel' => '<i class="uk-icon-angle-double-left"></i>',
'nextItemClass' => '', // blank out classes irrelevant to Uikit
'previousItemClass' => '',
'lastItemClass' => '',
);
$items = $pages->find("id>0, limit=10"); // replace id>0 with your selector
if($items->count()) {
$pager = $modules->get('Markup
Markup
class also inherits all the methods and properties of: Wire.Common
Name Return Summary string
Get URL for given pagination number array
Get all options or set options string
Render pagination markup (nothing) Wired to ProcessWire instance Method options
General options
Name Return Summary $pager->baseUrl string
The base URL from which the navigation item links will start (default=''). $pager->getVars array
GET vars that should appear in the pagination, or leave empty and populate $input->whitelist (recommended). $pager->numPageLinks int
The number of links that the pagination navigation should have, minimum 5 (default=10). $pager->page null
Page
The current Page, or leave NULL to autodetect. Markup options
Name Return Summary $pager->currentLinkMarkup string
Link markup for current page. Place {url} for href attribute and {out} for label content. (default="<a href='{url}'><span>{out}</span></a>"). $pager->itemMarkup string
List item markup. Place {class} for item class (required), and {out} for item content. (default="<li class='{class}' aria-label='{aria-label}'>{out}</li>"). $pager->linkMarkup string
Link markup. Place {url} for href attribute, and {out} for label content. (default="<a href='{url}'><span>{out}</span></a>"). $pager->listMarkup string
List container markup. Place {out} where you want the individual items rendered and {class} where you want the list class (default="<ul class='{class}' aria-label='{aria-label}'>{out}</ul>"). $pager->separatorItemMarkup string
Markup to use for the "..." separator item, or NULL to use $itemMarkup (default=NULL). Class options
Name Return Summary $pager->currentItemClass string
Class for current item (default='Markup $pager->firstItemClass string
Class for first item (default='Markup $pager->firstNumberItemClass string
Class for first numbered item (default='Markup $pager->lastItemClass string
Class for last item (default='Markup $pager->lastNumberItemClass string
Class for last numbered item (default='Markup $pager->listClass string
The class name to use in the $listMarkup (default='MarkupPageNav'). $pager->nextItemClass string
Class for next item (default='Markup $pager->previousItemClass string
Class for previous item (default='Markup $pager->separatorItemClass string
Class for separator item (default='Markup Label options
Name Return Summary $pager->currentItemAriaLabel string
Label announcing current page to screen readers (default='Page {n}, current page'). $pager->itemAriaLabel string
Label announcing page number to screen readers (default='Page {n}'). $pager->listAriaLabel string
Label announcing pagination to screen readers (default='Pagination links'). $pager->nextItemLabel string
label used for the 'Next' button (default='Next'). $pager->previousItemLabel string
label used for the 'Previous' button (default='Prev'). $pager->separatorItemLabel string
label used in the separator item (default='…'). Other options
Name Return Summary $pager->arrayToCSV bool
When arrays are present in getVars, they will be translated to CSV strings in the queryString "?var=a,b,c". If set to false, then arrays will be kept in traditional format: "?var[]=a&var[]=b&var=c". (default=true) $pager->itemsPerPage int
Get number of items to display per page (set automatically, pulled from limit=n). $pager->pageNum int
Get or set the current page number (1-based, set automatically). $pager->queryString string
Get or set query string used in links (set automatically, based on $input->whitelist or getVars array). $pager->totalItems int
Get total number of items to paginate (set automatically). Additional methods and properties
API reference based on ProcessWire core version 3.0.236