larawelp/pagination

为 LaraWelP 生成分页的简单库

v0.0.10 2023-08-20 20:35 UTC

This package is auto-updated.

Last update: 2024-08-30 01:38:34 UTC


README

这是一个用于创建分页的简单 PHP 库。

基本用法

以下是在 WordPress 中创建分页的示例。

global $wp_query;

// The total number of items
$total       = (int)$wp_query->found_posts;

// The number of items are going to be displayed per page.
$perPage     = (int)$wp_query->query_vars['posts_per_page'];

// The current page number.
$currentPage = (int)$wp_query->query_vars['paged'];

// additional options
$options     = ['urlStyle' => 'pretty'];


$paginator   = new Paginator($total, $perPage, $currentPage, $options);
    
echo $paginator->toHtml();

自定义标记

如果您不喜欢默认的标记,可以指定自己的视图文件来输出标记。

$paginator = new Paginator($total, $perPage, $currentPage, ['view'=> '/www/var/example.com/pagination.php']);

您还可以使用点表示法指定视图,例如 ['view'=> 'components.pagination'];使用点表示法,如果可能,它将尝试使用 Blade 模板

请参阅 预设视图 了解更多详情。

选项

onEachSide

中心链接两侧的链接数量。

type

渲染类型。

  • default
  • menu
  • simple

view

视图文件的路径。

可以是 blade 模板或常规 php 文件。
如果您想使用 php 文件,应在字符串末尾添加 .php

urlStyle

链接样式。

  • pretty: example.com/news/page/10
  • queryString: example.com/news/?page=10

nextPageText

下一页链接文本。

prevPageText

上一页链接文本。

path

用户定义的基础路径。

suffix

要添加到 URL 末尾的后缀。例如片段或查询字符串。