wnikk / smart-pagination
Reverse pagination for Laravel with SEO-friendly links and stable URLs
Requires
- php: ^8.0
- illuminate/support: ^11.0|^12.0
Requires (Dev)
README
SmartPagination is a Laravel Blade component that simplifies pagination rendering and adds support for reverse pagination (descending page numbers). Itβs designed to be flexible, SEO-friendly, and easy to customize.
Designed for blogs, news feeds, and any content that grows over time.
Features
- Stable URLs β older content stays on the same page even as new items are added
- SEO-Friendly β search engines retain indexing without shifting links
- User-Centric β newest content always appears on the first page
- Blade component - easy to use in Blade templates with Bootstrap-ready markup
- Flexible Routing - supports custom URL patterns via
page-pattern
- Preserves all other query parameters
- Reverse pagination support - show newest content first
π SEO-Friendly Pagination with Custom URL Patterns
SmartPagination allows you to generate clean, customizable,
and SEO-optimized pagination URLs for your applications.
Instead of relying on default query parameters like ?page=2
,
you can define your own URL patterns such as /blog/page-2
, /news-p3.html
, or even /archive-4y.html
.
β Why It Matters for SEO
Search engines prefer stable, predictable URLs. When paginated content (like blog posts, product listings, or news articles) grows over time, traditional pagination can cause older content to shift across pages β which may lead to:
- Duplicate indexing
- Loss of link equity
- Lower rankings for older content
With reverse pagination and custom URL patterns, you can ensure that:
- The first page always shows the newest content
- Older content remains accessible at the same URL
- Search engines consistently index the same pages over time
This improves crawl efficiency and preserves ranking signals for evergreen content.
π§ Examples of Custom Patterns
You can define your own pagePattern
using {page}
as a placeholder:
Pattern | Resulting URL (Page 2) |
---|---|
page-{page} |
/blog/page-2 |
news-p{page}.html |
/news/news-p2.html |
archive-{page}y |
/archive-2y |
π Reverse Pagination: Keep Your URLs Stable as Content Grows
Reverse pagination is a powerful feature that ensures your newest content always appears on the first page, while older content stays anchored to its original URLs. This is especially useful for blogs, news feeds, changelogs, or any time-sensitive content.
With reverse pagination, the first page always shows the latest items, and older pages remain unchanged β making your site more SEO-friendly.
π§ Examples of Reverse Pagination
You have 100 articles, sorted by newest first (DESC
), showing 10 per page.
π΄ With Reverse Pagination Disabled
Display Page | Real Page | Articles Shown |
---|---|---|
/news (page 1) |
page 1 | 91β100 (newest) |
/news/page-2 |
page 2 | 81β90 |
... | ... | ... |
/news/page-10 |
page 10 | 1β10 (oldest) |
Tomorrow you publish 10 more articles (total: 110):
Display Page | Real Page | Articles Shown |
---|---|---|
/news (page 1) |
page 1 | 101β110 (newest) |
/news/page-2 |
page 2 | 91β100 |
... | ... | ... |
/news/page-11 |
page 11 | 1β10 (still oldest) |
β With Reverse Pagination Enabled
Display Page | Real Page | Articles Shown |
---|---|---|
/news (page 10) |
page 1 | 91β100 (newest) |
/news/page-9 |
page 2 | 81β90 always on page-9 |
... | ... | ... |
/news/page-1 |
page 10 | 1β10 (oldest) always on page-1 |
Result:
- New content appears on the first page
- Older content stays at the same URL
- Search engines retain stable indexing
- No shifting of articles across pages
Installation
Install via Composer:
composer require wnikk/smart-pagination
Usage
For basic usage, you can use the smartPaginate
method on your Eloquent model.
This method will automatically handle pagination with the latest items first and generate reverse pagination links.
For example, if you have a Post
model and want to paginate the latest posts on controller:
$posts = \App\Models\Post::orderByDesc('created_at')->smartPaginate(10, reverse: true); $posts->withPath('/post', '/page-{page}.html');
In your Blade view (by default):
By default: {{ $posts->links() }}
Or your Blade custom view full version of params (SEO-friendly):
<x-smart-pagination :paginator="$posts" :reverse="true" :page-pattern="post-p{page}.html" :show-prev-next="true" />
Publish Configuration (optional)
Publish Configuration
php artisan vendor:publish --tag=smart-pagination-config
Publish Blade Views
php artisan vendor:publish --tag=smart-pagination-views
License
MIT