PHP Classes

Basic Paginator: Generate HTML links for paginating listings

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2013-12-13 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 201 All time: 7,583 This week: 1,205Up
Version License PHP version Categories  
basic-paginator 1.1GNU Lesser Genera...4.1HTML
Description Author  

This class can generate HTML links for paginating listings.

It takes as parameters the total number of entries in a listing, the limit of entries to show in each page and the base pagination link URL.

The class can generate a series of HTML links to browse the listing pages or links to go to the next, previous, first, last or any of specific page of the listing.

The name of the URL parameter that defines the current page is configurable.

Picture of Roger Baklund
  Performance   Level  
Name: Roger Baklund is available for providing paid consulting. Contact Roger Baklund .
Classes: 6 packages by
Country: Norway Norway
Age: 49
All time rank: 19927 in Norway Norway
Week rank: 1481 Up5 in Norway Norway Up
Innovation award
Innovation award
Nominee: 3x

BasicPagination class


- Easy to use, multi purpose, easily extendable
- High and low level usage
- Support for multiple languages
- Automatic handling of URL parameters
- Multiple simultaneous paginators 
- Variable width requirements (narrow/wide view)


You must provide the total number of items so that the total number of pages can be calculated.

$P = new BasicPagination($TotalItemCount);                        # specify the total number of items
$P = new BasicPagination($TotalItemCount,'target.php?');          # specify href prefix
$P = new BasicPagination($TotalItemCount,'?',20);                 # 20 items per page (default 10)
$P = new BasicPagination($TotalItemCount,'?',10,'o2');            # alternate offset parameter name
$P = new BasicPagination($TotalItemCount,'?',10,'offset',false);  # non-sticky URL parameters


All properties can be read and modified directly after instantiation. 
Properties 'link_class' and 'anchor' must be set after instantiation if they are to be used.

$P->max                   # the max offset value, equals $TotalItemCount
$P->baseurl               # prefix for all href attrs, default '?' 
$P->itemcount             # number of items per page, default 10
$P->offset_param_name     # name of URL parameter carrying offset, default 'offset'
$P->offset                # current offset, automatically read from $_REQUEST
$P->sticky                # stickyness of URL parameters, default true
$P->unstick               # array of URL parameter names to NOT use in links
$P->link_class            # class to be added to all links, default '' (none)
$P->anchor                # anchor to append to all links, default '' (none) 

High level methods:

$P->UnStick('foo');       # Drop URL parameter foo when making links
$P->PagesHTML();          # Returns the HTML page links
$P->PagesHTML(40);        # wide screen, up to 40 page links
$P->PagesHTML(12);        # narrow screen, max 12 page links
$P->PagesHTML(12,' - ');  # dash separator

Lower level methods:

$P->pagelinks()                   # returns page links only (not first/last/prev/next)
$P->make_URL($offset)             # returns an URL for use in a HREF or similar
$P->pagelink($page,$Label=false)  # returns a single page link
$P->firstpage()                   # link to the first page
$P->lastpage()                    # link to the last page
$P->nextpage()                    # link to the next page 
$P->prevpage()                    # link to the previous page

Methods meant for overriding:

$P->Label($i)       # Alternative text on page links, see demo
$P->Translate($str) # Implement your translations here, or trough a function named "translate"
$P->PagesHTML()     # Override to change link layout: first - prev - ..... - next - last
  Files folder image Files  
File Role Description
Plain text file BasicPagination.class.php Class Generic class for pagination
Accessible without login Plain text file readme.txt Doc. Class documentation
Accessible without login Plain text file test1_BasicPagination.php Example A basic test/demo script

 Version Control Unique User Downloads Download Rankings  
 0%Total:201All time:7,583
 This week:0This week:1,205Up