Last Updated: February 25, 2016
·
2.608K
· gosukiwi

PHP Pagination Generator

I find this class to be quite useful: https://gist.github.com/gosukiwi/7715487

Basically, it generates an unordered list ul with links to several pages, it's pretty cusomizable, it can output bootstrap style pagination markup, purecss markup, or any custom markup!

Here are some usage examples:

Generate PureCSS markup

$paginator = new Paginator();
$pagination = $paginator
    ->total(135)                // total items to paginate
    ->per_page(10)              // how many to show per page
    ->page_name('p')            // ?p=1
    ->ul_class('pure-paginator')    // css styles
    ->link_class('pure-button')
    ->link_active_class('pure-button-active')
    ->paginate();

Generate Bootstraps markup

$paginator = new Paginator();
$pagination = $paginator
    ->total(135)
    ->per_page(10)
    ->page_name('p')
    ->ul_class('pagination') // bootstraps only requires this
    ->paginate();