source file: /Zebra_Pagination.php
A generic, Twitter Bootstrap compatible, pagination script that automatically generates navigation links as well as next/previous page links, given the total number of records and the number of records to be shown per page. Useful for breaking large sets of data into smaller chunks, reducing network traffic and, at the same time, improving readability, aesthetics and usability.
Read more here
void __construct ( )
Constructor of the class.
Initializes the class and the default properties.
void always_show_navigation ( [ boolean $show = true] )
By default, the "previous page" and "next page" links are always shown.
By disabling this feature the "previous page" and "next page" links will only be shown if there are more pages than selectable_pages.
void avoid_duplicate_content ( [ boolean $avoid_duplicate_content = true] )
When you first access a page with navigation you have the same content as you have when you access the first page from navigation. For example http://www.mywebsite.com/list will have the same content as http://www.mywebsite.com/list?page=1.
From a search engine's point of view these are 2 distinct URLs having the same content and your pages will be penalized for that.
So, by default, in order to avoid this, the library will have for the first page (or last, if you are displaying links in reverse order) the same path as you have for when you are accessing the page for the first (un-paginated) time.
If you want to disable this behavior call this method with its argument set to FALSE.
void base_url ( [ string $base_url = ''] , [ boolean $preserve_query_string = true] )
The base URL to be used when generating the navigation links.
This is helpful for the case when, for example, the URL where the records are paginated may have parameters that are needed only once and need to be removed for any subsequent requests generated by pagination.
For example, suppose some records are paginated at http://yourwebsite/mypage/. When a record from the list is updated, the URL could become something like http://youwebsite/mypage/?action=updated. Based on the value of action a message would be shown to the user.
Because of the way this script works, the pagination links would become:
Because of this, whenever the user would paginate, the message would be shown to him again and again because action will be preserved in the URL!
The solution is to set the base_url to http://youwebsite/mypage/ and in this way, regardless of however will the URL be changed, the pagination links will always be in the form of
If you want to preserve the hash in the URL, make sure you load the zebra_pagination.js file!
integer get_page ( )
Returns the current page's number.
integer get_pages ( )
Returns the total number of pages, based on the total number of records and the number of records to be shown per page.
void labels ( [ string $previous = '«'] , [ string $next = '»'] )
Change the labels for the "previous page" and "next page" links.
void method ( [ string $method = 'get'] )
Set the method to be used for page propagation.
void navigation_position ( string $position )
By default, next/previous page links are shown on the outside of the links to individual pages.
These links can also be shown both on the left or on the right of the links to individual pages by setting the method's argument to "left" or "right" respectively.
void padding ( [ boolean $enabled = true] )
Sets whether page numbers should be prefixed by zeroes.
This is useful to keep the layout consistent by having the same number of characters for each page number.
void records ( integer $records )
Sets the total number of records that need to be paginated.
Based on this and on the value of records_per_page, the script will know how many pages there are.
void records_per_page ( integer $records_per_page )
Sets the number of records that are displayed on one page.
Based on this and on the value of records, the script will know how many pages there are.
void render ( [ boolean $return_output = false] )
Generates the output.
Make sure your script references the CSS file unless you are using Twitter Bootstrap!
void reverse ( [ boolean $reverse = false] )
By default, pagination links are shown in natural order, from 1 to the number of total pages.
Calling this method with the argument set to TRUE will generate links in reverse order, from the number of total pages to 1.
void selectable_pages ( integer $selectable_pages )
Sets the number of links to be displayed at once (besides "previous" and "next" links)
void set_page ( integer $page )
Sets the current page.
void trailing_slash ( boolean $enabled )
Enables or disables trailing slash on the generated URLs when method is "url".
Read more on the subject on Google Webmaster's official blog.
void variable_name ( string $variable_name )
Sets the variable name to be used for page propagation.