wnikk/smart-pagination 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wnikk/smart-pagination

Composer 安装命令:

composer require wnikk/smart-pagination

包简介

Reverse pagination for Laravel with SEO-friendly links and stable URLs

README 文档

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

wnikk/smart-pagination 适用场景与选型建议

wnikk/smart-pagination 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 wnikk/smart-pagination 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wnikk/smart-pagination 我们能提供哪些服务?
定制开发 / 二次开发

基于 wnikk/smart-pagination 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 37
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-18