PHP code example of rancoud / pagination

1. Go to this page and download the library: Download rancoud/pagination library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rancoud / pagination example snippets


composer 

$currentPage = 1;
$countElements = 10;
$countElementPerPage = 5;

$p = new Pagination();
$html = $p->generateHtml($currentPage, $countElements, $countElementPerPage);
echo $html;

$conf = [
    'url' => 'https://example.com/news/page/'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'url' => 'https://example.com/news/page/{{PAGE}}/?date=desc'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'url' => '{{PAGE}}?date=desc'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'show_all_links' => true
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);

$conf = [
    'use_previous' => true
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'always_use_previous' => true
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'use_next' => true
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'always_use_next' => true
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'use_dots' => true
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);

$conf = [
    'count_pages_pair_limit' => 1
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);

$conf = [
    'count_pages_pair_adjacent' => 1
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);

$conf = [
    'count_pages_pair_limit' => 0,
    'count_pages_pair_adjacent' => 0
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);

$conf = [
    'count_pages_pair_limit' => 2,
    'count_pages_pair_adjacent' => 2
];
echo (new Pagination($conf))->generateHtml(5, 300, 5);

$conf = [
    'use_previous' => true,
    'text_previous' => 'prev'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'use_next' => true,
    'text_next' => 'next'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'use_dots' => true,
    'text_dots' => 'dots'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);

$conf = [
    'text_page' => 'yolo'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'text_page' => 'yo {{PAGE}} lo'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'aria_label_link' => 'aria label link'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'aria_label_link' => 'aria label link {{PAGE}}'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'aria_label_current_link' => 'aria label current link'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'aria_label_current_link' => 'aria label current link {{PAGE}}'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'aria_label_nav' => 'aria label nav'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'use_previous' => true,
    'aria_label_previous' => 'prev'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'use_next' => true,
    'aria_label_next' => 'next'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'thousands_separator' => ';',
    'count_pages_pair_limit' => 1
];
echo (new Pagination($conf))->generateHtml(1, 1000, 1);

$conf = [
    'root_tag' => 'root'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'root_attrs' => 'data-root="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'use_nav' => false
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'nav_attrs' => 'data-item="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'item_tag' => 'item'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'item_attrs' => 'data-item="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'item_attrs' => 'data-item="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'item_attrs_current' => 'data-item-current="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'item_attrs_current' => 'data-item-current="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'use_previous' => true,
    'item_previous_attrs' => 'data-item-previous="attrs"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'use_previous' => true,
    'item_previous_attrs' => 'data-item-previous="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'always_use_previous' => true,
    'item_previous_attrs_disabled' => 'data-item-previous-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'always_use_previous' => true,
    'item_previous_attrs_disabled' => 'data-item-previous-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'use_next' => true,
    'item_next_attrs' => 'data-item-next="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'use_next' => true,
    'item_next_attrs' => 'data-item-next="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'always_use_next' => true,
    'item_next_attrs_disabled' => 'data-item-next-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'always_use_next' => true,
    'item_next_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'use_dots' => true,
    'item_dots_attrs' => 'data-item-dots="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);

$conf = [
    'link_tag' => 'link'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'link_attrs' => 'data-link="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'link_attrs' => 'data-link="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'link_attrs_current' => 'data-link-current="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'link_attrs_current' => 'data-link-current="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'always_use_previous' => true,
    'link_previous_attrs_disabled' => 'data-item-next-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'always_use_previous' => true,
    'link_previous_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'always_use_next' => true,
    'link_next_attrs_disabled' => 'data-item-next-disabled="attrs"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'always_use_next' => true,
    'link_next_attrs_disabled' => 'data-item-next-disabled="attrs {{PAGE}}"'
];
echo (new Pagination($conf))->generateHtml(2, 10, 5);

$conf = [
    'use_dots' => true,
    'dot_tag' => 'p'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);

$conf = [
    'use_dots' => true,
    'dot_attrs' => 'data-dot="attrs"'
];
echo (new Pagination($conf))->generateHtml(1, 30, 5);

$conf = [
    'use_pretty_html' => false
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'html_tab_sequence' => ''
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'html_initial_indentation' => 1
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'esc_attr' => false
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'esc_html' => false,
    'text_page' => '<em>{{PAGE}}</em>'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$conf = [
    'charset' => 'EUC-JP'
];
echo (new Pagination($conf))->generateHtml(1, 10, 5);

$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&#x20;page' (length=18)
      public 'href' => string '&#x23;' (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&#x20;1' (length=11)
          public 'href' => string '&#x23;' (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&#x20;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&#x20;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&#x20;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&#x20;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