rancoud / pagination
Pagination package
Installs: 6 750
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=7.4.0
- ext-mbstring: *
- rancoud/security: ^3.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16 || ^3.0
- phpunit/phpunit: ^9.1 || ^10.0 || ^11.0
- squizlabs/php_codesniffer: ^3.5
README
Generate HTML pagination for accessibility.
Dependencies
Security package: https://github.com/rancoud/Security
Installation
composer require rancoud/pagination
How to use it?
$currentPage = 1; $countElements = 10; $countElementPerPage = 5; $p = new Pagination(); $html = $p->generateHtml($currentPage, $countElements, $countElementPerPage); echo $html;
It will output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Lexicon
- Root represents
<ul>
- Item represents
<li>
- Link represents
<a>
Pagination Constructor
Settings
Optionnals
Pagination Methods
General Commands
- generateHtml(currentPage: int, countElements: int, countElementPerPage: int): string
- generateData(currentPage: int, countElements: int, countElementPerPage: int): array
Static methods
- countPages(countElements: int, countElementPerPage: int): int
- locateItemInPage(countElementPerPage: int, indexItem: int): int
Configuration Parameters
Url
- url (string) (example)
Behavior
- show_all_links (bool: false) (example)
- use_previous (bool: false) (example)
- always_use_previous (bool: false) (example)
- use_next (bool: false) (example)
- always_use_next (bool: false) (example)
- use_dots (bool: false) (example)
- count_pages_pair_limit (int: 0) (example)
- count_pages_pair_adjacent (int: 2) (example)
Labels
- text_previous (string: Previous page) (example)
- text_next (string: Next page) (example)
- text_dots (string: …) (example)
- text_page (string: {{PAGE}}) (example)
- aria_label_link (string: Goto page {{PAGE}}) (example)
- aria_label_current_link (string: Current page, page {{PAGE}}) (example)
- aria_label_nav (string: Pagination) (example)
- aria_label_previous (string: Previous page) (example)
- aria_label_next (string: Next page) (example)
- thousands_separator (string) (example)
HTML markup
Root
- root_tag (string: ul) (example)
- root_attrs (string) (example)
- use_nav (bool: true) (example)
- nav_attrs (string) (example)
Item
- item_tag (string: li) (example)
- item_attrs (string) (example)
- item_attrs_current (string) (example)
- item_previous_attrs (string) (example)
- item_previous_attrs_disabled (string) (example)
- item_next_attrs (string) (example)
- item_next_attrs_disabled (string) (example)
- item_dots_attrs (string) (example)
Link
- link_tag (string: a) (example)
- link_attrs (string) (example)
- link_attrs_current (string) (example)
- link_previous_attrs_disabled (string) (example)
- link_next_attrs_disabled (string) (example)
- dot_tag (string: span) (example)
- dot_attrs (string) (example)
Indentation
- use_pretty_html (bool: true) (example)
- html_tab_sequence (string: \t) (example)
- html_initial_indentation (int: 0) (example)
Security
You have to sanitize by yourself thoses parameters:
- nav_attrs
- root_attrs
- item_attrs
- item_attrs_current
- item_previous_attrs
- item_previous_attrs_disabled
- item_next_attrs
- item_next_attrs_disabled
- item_dots_attrs
- link_attrs
- link_attrs_current
- link_previous_attrs_disabled
- link_next_attrs_disabled
- dot_attrs
- html_tab_sequence
Examples
url
Page append at the end
Input
$conf = [ 'url' => 'https://example.com/news/page/' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="https://example.com/news/page/2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'url' => 'https://example.com/news/page/{{PAGE}}/?date=desc' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="https://example.com/news/page/2/?date=desc" aria-label="Page 2">2</a> </li> </ul> </nav>
After page replace with {{PAGE}} pattern
Input
$conf = [ 'url' => '{{PAGE}}?date=desc' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2?date=desc" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Url
show_all_links
Input
$conf = [ 'show_all_links' => true ]; echo (new Pagination($conf))->generateHtml(1, 30, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li> <a href="4" aria-label="Page 4">4</a> </li> <li> <a href="5" aria-label="Page 5">5</a> </li> <li> <a href="6" aria-label="Page 6">6</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
use_previous
Input
$conf = [ 'use_previous' => true ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Previous page">Previous page</a> </li> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
always_use_previous
Previous has aria-disabled=true
on link tag if there is no previous page
Input
$conf = [ 'always_use_previous' => true ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Previous page" aria-disabled="true">Previous page</a> </li> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
use_next
Input
$conf = [ 'use_next' => true ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="2" aria-label="Next page">Next page</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
always_use_next
Next has aria-disabled=true
on link tag if there is no next page
Input
$conf = [ 'always_use_next' => true ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> <li> <a href="#" aria-label="Next page" aria-disabled="true">Next page</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
use_dots
Input
$conf = [ 'use_dots' => true ]; echo (new Pagination($conf))->generateHtml(1, 30, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li aria-hidden="true"> <span>…</span> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
count_pages_pair_limit
Input
$conf = [ 'count_pages_pair_limit' => 1 ]; echo (new Pagination($conf))->generateHtml(5, 300, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li> <a href="4" aria-label="Page 4">4</a> </li> <li> <a href="#" aria-label="Page 5" aria-current="page">5</a> </li> <li> <a href="6" aria-label="Page 6">6</a> </li> <li> <a href="7" aria-label="Page 7">7</a> </li> <li> <a href="60" aria-label="Page 60">60</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
count_pages_pair_adjacent
Input
$conf = [ 'count_pages_pair_adjacent' => 1 ]; echo (new Pagination($conf))->generateHtml(5, 300, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="4" aria-label="Page 4">4</a> </li> <li> <a href="#" aria-label="Page 5" aria-current="page">5</a> </li> <li> <a href="6" aria-label="Page 6">6</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
count_pages_pair_adjacent + count_pages_pair_adjacent
count_pages_pair_limit 0 + count_pages_pair_adjacent 0
Input
$conf = [ 'count_pages_pair_limit' => 0, 'count_pages_pair_adjacent' => 0 ]; echo (new Pagination($conf))->generateHtml(5, 300, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 5" aria-current="page">5</a> </li> </ul> </nav>
count_pages_pair_limit 2 + count_pages_pair_adjacent 2
Input
$conf = [ 'count_pages_pair_limit' => 2, 'count_pages_pair_adjacent' => 2 ]; echo (new Pagination($conf))->generateHtml(5, 300, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li> <a href="4" aria-label="Page 4">4</a> </li> <li> <a href="#" aria-label="Page 5" aria-current="page">5</a> </li> <li> <a href="6" aria-label="Page 6">6</a> </li> <li> <a href="7" aria-label="Page 7">7</a> </li> <li> <a href="59" aria-label="Page 59">59</a> </li> <li> <a href="60" aria-label="Page 60">60</a> </li> </ul> </nav>
⏫ Configuration Parameters / Behavior
text_previous
Input
$conf = [ 'use_previous' => true, 'text_previous' => 'prev' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Previous page">prev</a> </li> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
text_next
Input
$conf = [ 'use_next' => true, 'text_next' => 'next' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="2" aria-label="Next page">next</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
text_dots
Input
$conf = [ 'use_dots' => true, 'text_dots' => 'dots' ]; echo (new Pagination($conf))->generateHtml(1, 30, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li aria-hidden="true"> <span>dots</span> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
text_page
Page append at the end
Input
$conf = [ 'text_page' => 'yolo' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">yolo 1</a> </li> <li> <a href="2" aria-label="Page 2">yolo 2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'text_page' => 'yo {{PAGE}} lo' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">yo 1 lo</a> </li> <li> <a href="2" aria-label="Page 2">yo 2 lo</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
aria_label_link
Input
$conf = [ 'aria_label_link' => 'aria label link' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="aria label link">2</a> </li> </ul> </nav>
With {{PAGE}} pattern
Input
$conf = [ 'aria_label_link' => 'aria label link {{PAGE}}' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="aria label link 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
aria_label_current_link
Input
$conf = [ 'aria_label_current_link' => 'aria label current link' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="aria label current link" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'aria_label_current_link' => 'aria label current link {{PAGE}}' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="aria label current link 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
aria_label_nav
Input
$conf = [ 'aria_label_nav' => 'aria label nav' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="aria label nav"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
aria_label_previous
Input
$conf = [ 'use_previous' => true, 'aria_label_previous' => 'prev' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="prev">Previous page</a> </li> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
aria_label_next
Input
$conf = [ 'use_next' => true, 'aria_label_next' => 'next' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="2" aria-label="next">Next page</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
thousands_separator
Input
$conf = [ 'thousands_separator' => ';', 'count_pages_pair_limit' => 1 ]; echo (new Pagination($conf))->generateHtml(1, 1000, 1);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li> <a href="1000" aria-label="Page 1000">1;000</a> </li> </ul> </nav>
⏫ Configuration Parameters / Labels
root_tag
Input
$conf = [ 'root_tag' => 'root' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <root> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </root> </nav>
⏫ Configuration Parameters / HTML markup / Root
root_attrs
Input
$conf = [ 'root_attrs' => 'data-root="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul data-root="attrs"> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Root
use_nav
Input
$conf = [ 'use_nav' => false ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul>
⏫ Configuration Parameters / HTML markup / Root
nav_attrs
Input
$conf = [ 'nav_attrs' => 'data-item="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination" data-item="attrs"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Root
item_tag
Input
$conf = [ 'item_tag' => 'item' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <item> <a href="#" aria-label="Page 1" aria-current="page">1</a> </item> <item> <a href="2" aria-label="Page 2">2</a> </item> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
item_attrs
Input
$conf = [ 'item_attrs' => 'data-item="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li data-item="attrs"> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'item_attrs' => 'data-item="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li data-item="attrs 2"> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
item_attrs_current
Input
$conf = [ 'item_attrs_current' => 'data-item-current="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li data-item-current="attrs"> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'item_attrs_current' => 'data-item-current="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li data-item-current="attrs 1"> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
item_previous_attrs
Input
$conf = [ 'use_previous' => true, 'item_previous_attrs' => 'data-item-previous="attrs"' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li data-item-previous="attrs"> <a href="1" aria-label="Previous page">Previous page</a> </li> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'use_previous' => true, 'item_previous_attrs' => 'data-item-previous="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li data-item-previous="attrs 1"> <a href="1" aria-label="Previous page">Previous page</a> </li> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
item_previous_attrs_disabled
Input
$conf = [ 'always_use_previous' => true, 'item_previous_attrs_disabled' => 'data-item-previous-disabled="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li data-item-previous-disabled="attrs"> <a href="#" aria-label="Previous page" aria-disabled="true">Previous page</a> </li> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'always_use_previous' => true, 'item_previous_attrs_disabled' => 'data-item-previous-disabled="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li data-item-previous-disabled="attrs 0"> <a href="#" aria-label="Previous page" aria-disabled="true">Previous page</a> </li> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
item_next_attrs
Input
$conf = [ 'use_next' => true, 'item_next_attrs' => 'data-item-next="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li data-item-next="attrs"> <a href="2" aria-label="Next page">Next page</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'use_next' => true, 'item_next_attrs' => 'data-item-next="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li data-item-next="attrs 2"> <a href="2" aria-label="Next page">Next page</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
item_next_attrs_disabled
Input
$conf = [ 'always_use_next' => true, 'item_next_attrs_disabled' => 'data-item-next-disabled="attrs"' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> <li data-item-next-disabled="attrs"> <a href="#" aria-label="Next page" aria-disabled="true">Next page</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'always_use_next' => true, 'item_next_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> <li data-item-next-disabled="attrs 2"> <a href="#" aria-label="Next page" aria-disabled="true">Next page</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
item_dots_attrs
Input
$conf = [ 'use_dots' => true, 'item_dots_attrs' => 'data-item-dots="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 30, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li data-item-dots="attrs" aria-hidden="true"> <span>…</span> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Item
link_tag
Input
$conf = [ 'link_tag' => 'link' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <link href="#" aria-label="Page 1" aria-current="page">1</link> </li> <li> <link href="2" aria-label="Page 2">2</link> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Link
link_attrs
Input
$conf = [ 'link_attrs' => 'data-link="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a data-link="attrs" href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'link_attrs' => 'data-link="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a data-link="attrs 2" href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Link
link_attrs_current
Input
$conf = [ 'link_attrs_current' => 'data-link-current="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a data-link-current="attrs" href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'link_attrs_current' => 'data-link-current="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a data-link-current="attrs 1" href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Link
link_previous_attrs_disabled
Input
$conf = [ 'always_use_previous' => true, 'link_previous_attrs_disabled' => 'data-item-next-disabled="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a data-item-next-disabled="attrs" href="#" aria-label="Previous page" aria-disabled="true">Previous page</a> </li> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'always_use_previous' => true, 'link_previous_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a data-item-next-disabled="attrs 0" href="#" aria-label="Previous page" aria-disabled="true">Previous page</a> </li> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Link
link_next_attrs_disabled
Input
$conf = [ 'always_use_next' => true, 'link_next_attrs_disabled' => 'data-item-next-disabled="attrs"' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> <li> <a data-item-next-disabled="attrs" href="#" aria-label="Next page" aria-disabled="true">Next page</a> </li> </ul> </nav>
Page replace with {{PAGE}} pattern
Input
$conf = [ 'always_use_next' => true, 'link_next_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"' ]; echo (new Pagination($conf))->generateHtml(2, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="1" aria-label="Page 1">1</a> </li> <li> <a href="#" aria-label="Page 2" aria-current="page">2</a> </li> <li> <a data-item-next-disabled="attrs 2" href="#" aria-label="Next page" aria-disabled="true">Next page</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Link
dot_tag
Input
$conf = [ 'use_dots' => true, 'dot_tag' => 'p' ]; echo (new Pagination($conf))->generateHtml(1, 30, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li aria-hidden="true"> <p>…</p> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Link
dot_attrs
Input
$conf = [ 'use_dots' => true, 'dot_attrs' => 'data-dot="attrs"' ]; echo (new Pagination($conf))->generateHtml(1, 30, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> <li> <a href="3" aria-label="Page 3">3</a> </li> <li aria-hidden="true"> <span data-dot="attrs">…</span> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Link
use_pretty_html
Input
$conf = [ 'use_pretty_html' => false ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"><ul><li><a href="#" aria-label="Page 1" aria-current="page">1</a></li><li><a href="2" aria-label="Page 2">2</a></li></ul></nav>
⏫ Configuration Parameters / HTML markup / Indentation
html_tab_sequence
Input
$conf = [ 'html_tab_sequence' => '' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Indentation
html_initial_indentation
Input
$conf = [ 'html_initial_indentation' => 1 ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Indentation
esc_attr
Input
$conf = [ 'esc_attr' => false ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Security
esc_html
Input
$conf = [ 'esc_html' => false, 'text_page' => '<em>{{PAGE}}</em>' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page"><em>1</em></a> </li> <li> <a href="2" aria-label="Page 2"><em>2</em></a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Security
charset
Input
$conf = [ 'charset' => 'EUC-JP' ]; echo (new Pagination($conf))->generateHtml(1, 10, 5);
Output
<nav aria-label="Pagination"> <ul> <li> <a href="#" aria-label="Page 1" aria-current="page">1</a> </li> <li> <a href="2" aria-label="Page 2">2</a> </li> </ul> </nav>
⏫ Configuration Parameters / HTML markup / Security
generateData output
$conf = [ 'always_use_previous' => true, 'always_use_next' => true, 'use_dots' => true, ] var_dump(new Pagination($conf))->generateData(1, 3000, 5); array (size=3) 'previous' => object(Rancoud\Pagination\Item)[2] public 'ariaLabel' => string 'Previous page' (length=18) public 'href' => string '#' (length=6) public 'itemAttrs' => string '' (length=0) public 'linkAttrs' => string '' (length=0) public 'text' => string 'Previous page' (length=13) public 'isCurrent' => boolean false public 'isDots' => boolean false public 'isDisabled' => boolean true public 'page' => int 0 'links' => array (size=4) 0 => object(Rancoud\Pagination\Item)[4] public 'ariaLabel' => string 'Page 1' (length=11) public 'href' => string '#' (length=6) public 'itemAttrs' => string '' (length=0) public 'linkAttrs' => string '' (length=0) public 'text' => string '1' (length=1) public 'isCurrent' => boolean true public 'isDots' => boolean false public 'isDisabled' => boolean false public 'page' => int 1 1 => object(Rancoud\Pagination\Item)[5] public 'ariaLabel' => string 'Page 2' (length=11) public 'href' => string '2' (length=1) public 'itemAttrs' => string '' (length=0) public 'linkAttrs' => string '' (length=0) public 'text' => string '2' (length=1) public 'isCurrent' => boolean false public 'isDots' => boolean false public 'isDisabled' => boolean false public 'page' => int 2 2 => object(Rancoud\Pagination\Item)[6] public 'ariaLabel' => string 'Page 3' (length=11) public 'href' => string '3' (length=1) public 'itemAttrs' => string '' (length=0) public 'linkAttrs' => string '' (length=0) public 'text' => string '3' (length=1) public 'isCurrent' => boolean false public 'isDots' => boolean false public 'isDisabled' => boolean false public 'page' => int 3 3 => object(Rancoud\Pagination\Item)[7] public 'ariaLabel' => string 'Page 4' (length=11) public 'href' => string '4' (length=1) public 'itemAttrs' => string '' (length=0) public 'linkAttrs' => string '' (length=0) public 'text' => string '…' (length=3) public 'isCurrent' => boolean false public 'isDots' => boolean true public 'isDisabled' => boolean false public 'page' => int 4 'next' => object(Rancoud\Pagination\Item)[8] public 'ariaLabel' => string 'Next page' (length=14) public 'href' => string '2' (length=1) public 'itemAttrs' => string '' (length=0) public 'linkAttrs' => string '' (length=0) public 'text' => string 'Next page' (length=9) public 'isCurrent' => boolean false public 'isDots' => boolean false public 'isDisabled' => boolean false public 'page' => int 2
How to Dev
composer ci
for php-cs-fixer and phpunit and coverage
composer lint
for php-cs-fixer
composer test
for phpunit and coverage