PHP code example of benhall14 / php-pagination

1. Go to this page and download the library: Download benhall14/php-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/ */

    

benhall14 / php-pagination example snippets


$pagination = new Pagination();
$pagination->total(100)->output();

# sets the total number of items in the collection - e.g. 100
$pagination->total(number);

# sets the current page. By default, the class looks for the page value in the GET query string.
$pagination->page(number);

# sets the number of items to show per page. Default = 20
$pagination->perPage(number);

# sets the separator (if using). Default '...'
$pagination->separator(text);

# sets the screen reader class. Default 'true', but you may need to set it to false if you are using your own custom css.
$pagination->screenReader(bool);

# sets the Bootstrap 4 pagination link class to small
$pagination->small();

# sets the Bootstrap 4 pagination link class to medium
$pagination->medium();

# sets the Bootstrap 4 pagination link class to large
$pagination->large();

# sets the Bootstrap 4 alignment class to left
$pagination->alignLeft();

# sets the Bootstrap 4 alignment class to center
$pagination->alignCenter();

# sets the Bootstrap 4 alignment class to right
$pagination->alignRight();

# sets the flag to show the separator
$pagination->showSeparator();

# sets the flag to hide the separator
$pagination->hideSeparator();

# sets the next text string - Default: 'Next'
$pagination->nextText(text);

# sets the previous text string - Default: 'Previous'
$pagination->previousText(text);

# hides the 'Next' link
$pagination->hideNext();

# shows the 'Next' link
$pagination->showNext();

# hides the 'Previous' link
$pagination->hidePrevious();

# shows the 'Previous' link
$pagination->showPrevious();

# sets a prefix text for each page link: {prefix} {page number} {suffix}
$pagination->pagePrefix(text);

# sets a suffix text for each page link: {prefix} {page number} {suffix}
$pagination->pageSuffix(text);

# sets the flag to retain the query string for each page link.
$pagination->retainQueryString();

# sets the flag to ignore the query string when building the links
$pagination->dismissQueryString();

# sets the number of pages BEFORE the separator
$pagination->pagesBeforeSeparator(number);

# sets the number of pages AROUND the active page
$pagination->pagesAroundActive(number);

# sets the URL pattern - Default $pattern: ?page=(:num)- $replacement: (:num)
$pagination->pattern($pattern, $replacement);
# The class will replace the $replacement token in the $pattern with the actual page number