{"id":17976058,"url":"https://github.com/stefangabos/zebra_pagination","last_synced_at":"2026-02-09T14:10:56.992Z","repository":{"id":9519324,"uuid":"11417286","full_name":"stefangabos/Zebra_Pagination","owner":"stefangabos","description":"A generic, Twitter Bootstrap compatible, pagination library for automatically generating navigation links","archived":false,"fork":false,"pushed_at":"2024-06-19T16:30:02.000Z","size":312,"stargazers_count":113,"open_issues_count":0,"forks_count":78,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-28T23:09:33.792Z","etag":null,"topics":["pagination","pagination-generator","pagination-library","pagination-links","pagination-script","php"],"latest_commit_sha":null,"homepage":"https://stefangabos.github.io/Zebra_Pagination/Zebra_Pagination/Zebra_Pagination.html","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefangabos.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"stefangabos","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2013-07-15T07:26:06.000Z","updated_at":"2025-01-29T19:32:28.000Z","dependencies_parsed_at":"2024-01-18T23:04:53.301Z","dependency_job_id":"ce35df83-d354-423e-80a3-e93aa16ba4ec","html_url":"https://github.com/stefangabos/Zebra_Pagination","commit_stats":{"total_commits":146,"total_committers":4,"mean_commits":36.5,"dds":"0.020547945205479423","last_synced_commit":"3c82a19bb5a9955c29cdbda4b8c63c985b0a5ad2"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefangabos","download_url":"https://codeload.github.com/stefangabos/Zebra_Pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266565,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pagination","pagination-generator","pagination-library","pagination-links","pagination-script","php"],"created_at":"2024-10-29T17:21:45.932Z","updated_at":"2026-02-09T14:10:56.933Z","avatar_url":"https://github.com/stefangabos.png","language":"PHP","funding_links":["https://github.com/sponsors/stefangabos","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=SKXN7C6PPH6FL"],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/stefangabos/zebrajs/blob/master/docs/images/logo.png\" alt=\"zebrajs\" align=\"right\"\u003e\n\n# Zebra Pagination \u0026nbsp;[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=A+generic,+Twitter+Bootstrap+compatible,+pagination+library+that+automatically+generates+navigation+links\u0026url=https://github.com/stefangabos/Zebra_Pagination\u0026via=stefangabos\u0026hashtags=php)\n\n*A generic, Twitter Bootstrap compatible, pagination library that automatically generates navigation links*\n\n[![Latest Stable Version](https://poser.pugx.org/stefangabos/zebra_pagination/v/stable)](https://packagist.org/packages/stefangabos/zebra_pagination) [![Total Downloads](https://poser.pugx.org/stefangabos/zebra_pagination/downloads)](https://packagist.org/packages/stefangabos/zebra_pagination) [![Monthly Downloads](https://poser.pugx.org/stefangabos/zebra_pagination/d/monthly)](https://packagist.org/packages/stefangabos/zebra_pagination) [![Daily Downloads](https://poser.pugx.org/stefangabos/zebra_pagination/d/daily)](https://packagist.org/packages/stefangabos/zebra_pagination) [![License](https://poser.pugx.org/stefangabos/zebra_pagination/license)](https://packagist.org/packages/stefangabos/zebra_pagination)\n\nA generic, [Twitter Bootstrap](http://getbootstrap.com) compatible (versions 3, 4 and 5), 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.\n\nAdheres to pagination best practices (provides large clickable areas, doesn't use underlines, the selected page is clearly highlighted, page links are spaced out, provides \"previous page\" and \"next page\" links, provides \"first page\" and \"last page\" links - as outlined in an article by Faruk Ates from 2007, which can now be found [here](https://gist.github.com/622561), can generate links both in natural as well as in reverse order, can be easily, localized, supports different positions for next/previous page buttons, supports page propagation via GET or via URL rewriting, is SEO-friendly, and the appearance is easily customizable through CSS.\n\n\u003e Please note that this is a *generic* pagination script, meaning that it does not display any records and it does not have any dependencies on database connections or SQL queries, making it very flexible! It is up to the developer to fetch the actual data and display it based on the information returned by this pagination script. The advantage is that it can be used to paginate over records coming from any source like arrays or databases.\n\nThe code is heavily commented and generates no warnings/errors/notices when PHP's error reporting level is set to E_ALL.\n\n## Features\n\n- it is a generic library: can be used to paginate records both from an array or from a database\n- it automatically generates navigation links, given the total number of items and the number of items per page (examples of best practices are also included)\n- navigation links can be generated in natural or in reverse order\n- it is SEO-friendly - it solves the problem of duplicate content on the first page without navigation and the first page having the page number in the URL\n- appearance is easily customizable through CSS\n- compatible with [Twitter Bootstrap](http://getbootstrap.com) versions 3, 4 and 5\n- code is heavily commented and generates no warnings/errors/notices when PHP's error reporting level is set to E_ALL\n- has [awesome documentation](https://stefangabos.github.io/Zebra_Pagination/Zebra_Pagination/Zebra_Pagination.html)\n\n## :notebook_with_decorative_cover: Documentation\n\nCheck out the [awesome documentation](https://stefangabos.github.io/Zebra_Pagination/Zebra_Pagination/Zebra_Pagination.html)!\n\n## 🎂 Support the development of this project\n\nYour support means a lot and it keeps me motivated to keep working on open source projects.\u003cbr\u003e\nIf you like this project please ⭐ it by clicking on the star button at the top of the page.\u003cbr\u003e\nIf you are feeling generous, you can buy me a coffee by donating through PayPal, or you can become a sponsor.\u003cbr\u003e\nEither way - **Thank you!** 🎉\n\n[\u003cimg src=\"https://img.shields.io/github/stars/stefangabos/zebra_pagination?color=green\u0026label=star%20it%20on%20GitHub\" width=\"132\" height=\"20\" alt=\"Star it on GitHub\"\u003e](https://github.com/stefangabos/Zebra_Pagination) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=SKXN7C6PPH6FL) [\u003cimg src=\"https://img.shields.io/badge/-Sponsor-fafbfc?logo=GitHub%20Sponsors\"\u003e](https://github.com/sponsors/stefangabos)\n\n## Requirements\n\nPHP 5+\n\n## Installation\n\nYou can install Zebra Pagination via [Composer](https://packagist.org/packages/stefangabos/zebra_pagination)\n\n```bash\n# get the latest stable release\ncomposer require stefangabos/zebra_pagination\n\n# get the latest commit\ncomposer require stefangabos/zebra_pagination:dev-master\n```\n\nOr you can install it manually by downloading the latest version, unpacking it, and then including it in your project\n\n```php\nrequire_once 'path/to/Zebra_Pagination.php';\n```\n\n## How to use\n\nMake sure that in the \u003chead\u003e of your page you have\n\n```html\n\u003c!-- you don't need this if you're using Twitter Bootstrap --\u003e\n\u003clink rel=\"stylesheet\" href=\"path/to/zebra_pagination.css\" type=\"text/css\"\u003e\n```\n\nIf you want to preserve hashes in the URL, also include the JavaScript file – simply including it will suffice;\n(jQuery needs to also be loaded before loading this file)\n\n```javascript\n\u003cscript src=\"path/to/zebra_pagination.js\"\u003e\u003c/script\u003e\n```\n\nPaginate data from an array:\n\n**The PHP**\n\n```php\n\u003c?php\n\n// let's paginate data from an array...\n$countries = array(\n    // array of countries\n);\n\n// how many records should be displayed on a page?\n$records_per_page = 10;\n\n// include the pagination class\n// (you don't need this if you are using composer)\nrequire 'path/to/Zebra_Pagination.php';\n\n// instantiate the pagination object\n$pagination = new Zebra_Pagination();\n\n// the number of total records is the number of records in the array\n$pagination-\u003erecords(count($countries));\n\n// records per page\n$pagination-\u003erecords_per_page($records_per_page);\n\n// here's the magic: we need to display *only* the records for the current page\n$countries = array_slice(\n    $countries,\n    (($pagination-\u003eget_page() - 1) * $records_per_page),\n    $records_per_page\n);\n\n?\u003e\n\n\u003ctable\u003e\n    \u003cthead\u003e\n    \u003ctr\u003e\n        \u003cth\u003eCountry\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n    \u003c?php foreach ($countries as $index =\u003e $country): ?\u003e\n    \u003ctr\u003c?php echo $index % 2 ? ' class=\"even\"' : ''; ?\u003e\u003e\n        \u003ctd\u003e\u003c?php echo $country; ?\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003c?php endforeach; ?\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c?php\n\n// render the pagination links\n$pagination-\u003erender();\n```\n\nWould result is something like\n\n![Zebra_Pagination, default layout](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-natural.png?raw=true)\n\nYou can set the navigation links' position to the left or to the right of the pagination links using the [navigation_position()](https://stefangabos.github.io/Zebra_Pagination/Zebra_Pagination/Zebra_Pagination.html#methodnavigation_position) method:\n\n```php\n$pagination-\u003enavigation_position('left');\n```\n![Zebra_Pagination, position next/previous buttons on the left](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-buttons-left.png?raw=true)\n\n```php\n$pagination-\u003enavigation_position('right');\n```\n![Zebra_Pagination, position next/previous buttons on the right](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-buttons-right.png?raw=true)\n\nLabels for \"Previous\" and \"Next\" links can be changed with the [labels()](https://stefangabos.github.io/Zebra_Pagination/Zebra_Pagination/Zebra_Pagination.html#methodlabels) method:\n\n```php\n$pagination-\u003elabels('Previous', 'Next');\n```\n![Zebra_Pagination, using labels for navigating to next/previous pages](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-labels.png?raw=true)\n\nYou can also have HTML markup as labels making it easy to include font icons like the ones from [Font Awesome](https://fontawesome.com/)\n\n```php\n$pagination-\u003elabels('\u003ci class=\"fa fa-arrow-left\"\u003e\u003c/i\u003e', '\u003ci class=\"fa fa-arrow-right\"\u003e\u003c/i\u003e');\n```\n![Zebra_Pagination, using icons for navigating to next/previous pages](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-labels-icon-font.png?raw=true)\n\nUsing *condensed navigation* where only links to first, last, next and previous pages are available. Useful when there isn't enough space for a full blown pagination.\n\n```php\n$pagination-\u003econdensed();\n```\n![Zebra_Pagination, condensed navigation](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-condensed.png?raw=true)\n\nUsing *extra condensed navigation* where only links next and previous pages are available. Useful when there isn't enough space for a full blown pagination.\n\n```php\n$pagination-\u003econdensed(true);\n```\n![Zebra_Pagination, condensed navigation](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-very-condensed.png?raw=true)\n\nPaginate data from MySQL:\n\n```php\n\u003c?php\n\n// connect to a database\n$connection = mysqli_connect($host, $username, $password, $database);\n\n// how many records should be displayed on a page?\n$records_per_page = 10;\n\n// include the pagination class\n// (you don't need this if you are using composer)\nrequire 'path/to/Zebra_Pagination.php';\n\n// instantiate the pagination object\n$pagination = new Zebra_Pagination();\n\n// the MySQL statement to fetch the rows\n$sql = '\n    SELECT\n        country\n    FROM\n        countries\n    LIMIT\n        ' . (($pagination-\u003eget_page() - 1) * $records_per_page) . ', ' . $records_per_page . '\n';\n\n// execute the MySQL query\n// (you will use mysqli or PDO here, but you get the idea)\n$result = mysqli_query($connection, $sql) or die(mysqli_error($connection));\n\n// fetch the total number of records in the table\n$rows = mysqli_fetch_assoc(mysqli_query($connection, 'SELECT COUNT(*) AS rows FROM countries'));\n\n// pass the total number of records to the pagination class\n$pagination-\u003erecords($rows['rows']);\n\n// records per page\n$pagination-\u003erecords_per_page($records_per_page);\n\n?\u003e\n\n\u003ctable\u003e\n    \u003cthead\u003e\n    \u003ctr\u003e\n        \u003cth\u003eCountry\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n    \u003c?php $index = 0; while ($row = mysqli_fetch_assoc($result)): ?\u003e\n    \u003ctr\u003c?php echo $index++ % 2 ? ' class=\"even\"' : ''; ?\u003e\u003e\n        \u003ctd\u003e\u003c?php echo $row['country']; ?\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003c?php endwhile; ?\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c?php\n\n// render the pagination links\n$pagination-\u003erender();\n```\n\nPaginate data from MySQL in reverse order:\n\n```php\n\u003c?php\n\n// connect to a database\n$connection = mysqli_connect($host, $username, $password, $database);\n\n// how many records should be displayed on a page?\n$records_per_page = 10;\n\n// include the pagination class\n// (you don't need this if you are using Composer)\nrequire 'path/to/Zebra_Pagination.php';\n\n// instantiate the pagination object\n$pagination = new Zebra_Pagination();\n\n// show records in reverse order\n$pagination-\u003ereverse(true);\n\n// when showing records in reverse order, we need to know the total number\n// of records from the beginning\n$result = mysqli_query($connection, 'SELECT COUNT(*) AS rows FROM countries'))) or die (mysqli_error());\n\n// pass the total number of records to the pagination class\n$pagination-\u003erecords(array_pop(mysqli_fetch_assoc($result)));\n\n// records per page\n$pagination-\u003erecords_per_page($records_per_page);\n\n// the MySQL statement to fetch the rows\n// note the LIMIT - use it exactly like that!\n// also note that we're ordering data descendingly - most important when we're\n// showing records in reverse order!\n$sql = '\n    SELECT\n        country\n    FROM\n        countries\n    ORDER BY\n        country DESC\n    LIMIT\n        ' . (($pagination-\u003eget_pages() - $pagination-\u003eget_page()) * $records_per_page) . ', ' . $records_per_page . '\n';\n\n// run the query\nmysqli_query($connection. $sql) or die(mysqli_error($connection));\n\n?\u003e\n\n\u003ctable\u003e\n    \u003cthead\u003e\n    \u003ctr\u003e\n        \u003cth\u003eCountry\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n    \u003c?php $index = 0; while ($row = mysqli_fetch_assoc($result)): ?\u003e\n    \u003ctr\u003c?php echo $index++ % 2 ? ' class=\"even\"' : ''; ?\u003e\u003e\n        \u003ctd\u003e\u003c?php echo $row['country']; ?\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003c?php endwhile; ?\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c?php\n\n// render the pagination links\n$pagination-\u003erender();\n```\n\nWould result in something like\n\n![Zebra_Pagination](https://github.com/stefangabos/Zebra_Pagination/blob/master/docs/media/example-reversed.png?raw=true)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefangabos%2Fzebra_pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefangabos%2Fzebra_pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefangabos%2Fzebra_pagination/lists"}