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.137

Twitter updates

  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019
  • We added WebP image support this year and many have been adopting it in existing projects. We look at a process used for migrating existing websites to WebP images— from preliminary considerations to implementation & testing, w/lots of tips & tricks too: More
    16 August 2019

Latest news

  • ProcessWire Weekly #279
    This week in the 279th issue of ProcessWire Weekly we're going to introduce some of the latest third party modules out there, and highlight a brand new site of the week. Read on!
    Weekly.pw / 14 September 2019
  • ProcessWire 3.0.141 core updates
    This week’s dev branch version brings you improvements to ProcessWire’s $input->cookie API variable, adds a new hook, and now lets you modify system URLs and paths at runtime, along with a few examples to demonstrate just how useful this can be. 
    Blog / 20 September 2019
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH