PHPackages                             delight-im/pagination - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. delight-im/pagination

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

delight-im/pagination
=====================

Helps partition items across pages and generates sets of convenient controls for navigation

v1.0.0(1y ago)411MITPHPPHP &gt;=5.6.0

Since Jul 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/delight-im/PHP-Pagination)[ Packagist](https://packagist.org/packages/delight-im/pagination)[ Docs](https://github.com/delight-im/PHP-Pagination)[ RSS](/packages/delight-im-pagination/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

PHP-Pagination
==============

[](#php-pagination)

Helps partition items across pages and generates sets of convenient controls for navigation

Requirements
------------

[](#requirements)

- PHP 5.6.0+

Installation
------------

[](#installation)

1. Include the library via Composer [\[?\]](https://github.com/delight-im/Knowledge/blob/master/Composer%20(PHP).md):

    ```
    $ composer require delight-im/pagination
    ```
2. Include the Composer autoloader:

    ```
    require __DIR__ . '/vendor/autoload.php';
    ```

Usage
-----

[](#usage)

### Creating an instance

[](#creating-an-instance)

```
$numberOfItems = 1000;
$pagination = new Pagination($numberOfItems);

// or

$numberOfItems = 1000;
$itemsPerPage = 30;
$pagination = new Pagination($numberOfItems, $itemsPerPage);

// or

$numberOfItems = 1000;
$itemsPerPage = 30;
$currentPage = 10;
$pagination = new Pagination(
    $numberOfItems,
    $itemsPerPage,
    $currentPage
);
```

If you don’t specify the current page explicitly in the third argument, it will be auto-detected from the `page` or `p` query parameters, if available.

### Displaying a pagination bar

[](#displaying-a-pagination-bar)

#### Simple HTML

[](#simple-html)

```
$targetUrl = '/products/drinks/?page={page}';
echo $pagination->toHtml($targetUrl);

// or

$targetUrl = '/products/drinks/?page={page}';
$numberOfControls = 11;
$showFirstLast = true;
$showPreviousNext = true;
$previousLabel = '« Previous';
$nextLabel = 'Next »';
echo $pagination->toHtml(
    $targetUrl,
    $numberOfControls,
    $showFirstLast,
    $showPreviousNext,
    $previousLabel,
    $nextLabel
);
```

#### Bootstrap front-end framework

[](#bootstrap-front-end-framework)

```
$targetUrl = '/products/drinks/?page={page}';
echo $pagination->toHtmlForBootstrap5($targetUrl);

// or

$targetUrl = '/products/drinks/?page={page}';
$displaySize = 0; // -1 = small, 0 = normal, +1 = large
$numberOfControls = 11;
$showFirstLast = true;
$showPreviousNext = true;
$previousLabel = '« Previous';
$nextLabel = 'Next »';
echo $pagination->toHtmlForBootstrap5(
    $targetUrl,
    $displaySize,
    $numberOfControls,
    $showFirstLast,
    $showPreviousNext,
    $previousLabel,
    $nextLabel
);
```

Instead of `Pagination#toHtmlForBootstrap5`, you can also call `Pagination#toHtmlForBootstrap4` or `Pagination#toHtmlForBootstrap3` with the same method signature.

#### Custom HTML

[](#custom-html)

First, generate an array of `PaginationElement` objects:

```
$controls = $pagination->build();

// or

$numberOfControls = 11;
$showFirstLast = true;
$showPreviousNext = true;
$previousLabel = '« Previous';
$nextLabel = 'Next »';
$controls = $pagination->build(
    $numberOfControls,
    $showFirstLast,
    $showPreviousNext,
    $previousLabel,
    $nextLabel
);
```

Then turn these `PaginationElement` objects into custom HTML:

```
foreach ($controls as $control) {
    // $control->getLabel();
    // $control->getPage();
    // $control->isSelected();
    // $control->isDisabled();
}
```

### Adjusting database queries

[](#adjusting-database-queries)

```
$pagination->getOffset();
// int(1000)

$pagination->getLimit();
// int(25)
```

You can use these two values in your database queries, for example like this:

```
$sql = "SELECT * FROM products LIMIT " . $pagination->getOffset() . ", " . $pagination->getLimit();

// or

$sql = "SELECT * FROM products LIMIT " . $pagination->getLimit() . " OFFSET " . $pagination->getOffset();
```

Contributing
------------

[](#contributing)

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.

License
-------

[](#license)

This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

710d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6597567?v=4)[delight.im](/maintainers/delight-im)[@delight-im](https://github.com/delight-im)

---

Top Contributors

[![ocram](https://avatars.githubusercontent.com/u/1681478?v=4)](https://github.com/ocram "ocram (1 commits)")

---

Tags

pagepaginatorpaginationpaging

### Embed Badge

![Health badge](/badges/delight-im-pagination/health.svg)

```
[![Health](https://phpackages.com/badges/delight-im-pagination/health.svg)](https://phpackages.com/packages/delight-im-pagination)
```

###  Alternatives

[pagerfanta/pagerfanta

Pagination for PHP

45452.0M283](/packages/pagerfanta-pagerfanta)[beberlei/porpaginas

Library that generically solves several pagination issues with DAO/repository abstractions.

163643.5k14](/packages/beberlei-porpaginas)[jasongrimes/paginator

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

4091.3M22](/packages/jasongrimes-paginator)[stefangabos/zebra_pagination

A generic, Twitter Bootstrap compatible, PHP pagination library that automatically generates navigation links

11923.8k](/packages/stefangabos-zebra-pagination)[usmanhalalit/strana

Pagination library for PHP, framework agnostic, with built-in adapters for Doctrine, Eloquent, Pixie and PHP Array.

957.4k4](/packages/usmanhalalit-strana)[2createstudio/carbon-pagination

A handy WordPress library for building all kinds of paginations.

152.4k](/packages/2createstudio-carbon-pagination)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
