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, minimum 5 (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.236

Latest news

  • ProcessWire Weekly #551
    In the 551st issue of ProcessWire Weekly we'll check out what's new in the core this week, share a new weekly poll, and more. Read on!
    Weekly.pw / 1 December 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK