MarkupPagerNav class

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 MarkupPageArray module). Note that in this case, it’s not necessary to load the MarkupPagerNav module yourself:

$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>";
}

It’s common to specify different markup and/or classes specific to the need when rendering pagination. This is done by providing an $options array to the MarkupPagerNav::render() 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>&hellip;</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('MarkupPagerNav');
  echo "<ul>" . $items->each("<li>{title}</li>") . "</ul>";
  echo $pager->render($items, $options); // provide the $options array
} else {
  echo "<p>Sorry there were no items found</p>";
}

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 MarkupPagerNav class also inherits all the methods and properties of: Wire.

Show $var?             Show args?        

General options

NameReturnSummary 
$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 (default=10).  
$pager->page null Page The current Page, or leave NULL to autodetect.  

Markup options

NameReturnSummary 
$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

NameReturnSummary 
$pager->currentItemClass string Class for current item (default='MarkupPagerNavOn').  
$pager->firstItemClass string Class for first item (default='MarkupPagerNavFirst').  
$pager->firstNumberItemClass string Class for first numbered item (default='MarkupPagerNavFirstNum').  
$pager->lastItemClass string Class for last item (default='MarkupPagerNavLast').  
$pager->lastNumberItemClass string Class for last numbered item (default='MarkupPagerNavLastNum').  
$pager->listClass string The class name to use in the $listMarkup (default='MarkupPageNav').  
$pager->nextItemClass string Class for next item (default='MarkupPagerNavNext').  
$pager->previousItemClass string Class for previous item (default='MarkupPagerNavPrevious').  
$pager->separatorItemClass string Class for separator item (default='MarkupPagerNavSeparator').  

Label options

NameReturnSummary 
$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='&hellip;').  

Other options

NameReturnSummary 
$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

In addition to the methods and properties above, MarkupPagerNav also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.135

Twitter updates

  • New post: Version 3.0.135 of ProcessWire on the dev branch focuses on some .htaccess updates, adds clarity to debug mode, and improves upon the installer— More
    5 July 2019
  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019

Latest news

  • ProcessWire Weekly #270
    This week in the 270th issue of ProcessWire Weekly we're going to cover the SearchEngine module, feature some recent support forum highlights, and introduce a brand new site of the week. Read on!
    Weekly.pw / 13 July 2019
  • ProcessWire 3.0.135 core updates
    Version 3.0.135 of ProcessWire on the dev branch focuses on .htaccess updates, adds additional layers of security, adds clarity to debug mode, and improves upon the installer.
    Blog / 3 July 2019
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani