regionhalland/region-halland-plugin-array-pagination

用于在数组中创建分页的特殊功能

安装数: 1,163

依赖项: 1

建议者: 0

安全: 0

类型:wordpress-plugin

v1.4.0 2020-07-14 14:10 UTC

This package is auto-updated.

Last update: 2024-09-14 23:12:43 UTC


README

如何使用Region Halland的插件"RhArrayPagination"

以下是使用"RhArrayPagination"插件的操作指南。

用途

此插件允许分页数组。功能会跟踪在数组中的位置以及要显示哪些条目

许可证模型

此插件使用GPL-3.0许可证模型。您可以通过随附的文件了解更多关于此许可证模型的信息

LICENSE (https://regionhalland.visualstudio.com/public.RhWpPlugIns/_git/RhArrayPagination?path=%2FLICENSE&version=GBmaster)

安装和激活

A) Hämta pluginen via Git eller läs in det med Composer
B) Installera Region Hallands plugin i Wordpress plugin folder
C) Aktivera pluginet inifrån Wordpress admin

通过Git获取插件

git clone https://regionhalland.visualstudio.com/public.RhWpPlugIns/_git/RhArrayPagination

通过composer导入插件

以下两个部分需要添加到您的composer文件中

Repositories = 插件存储的位置,在本例中是GitHub

"repositories": [
  {
    "type": "vcs",
    "url": "https://regionhalland.visualstudio.com/public.RhWpPlugIns/_git/RhArrayPagination"
  }
],

Require = 指定要使用的插件版本,在本例中是版本1.0.0

注意!请确保您获取的是最新版本。

"require": {
  "regionhalland/region-halland-array-pagination": "1.0.0"
},

获取分页数组并将其放置在变量$myPagination中

  • 首先获取一个任意数组
  • 然后调用函数"get_region_halland_array_pagination()"
  • 需要指定三个值,其中只有第一个是必需的
  • 数组中的条目数,即可以表示为"count(ARRAY)"
  • 每页显示的条目数,未指定时默认为5
  • 查询字符串的名称,默认为"sida"
@php($myPagination = get_region_halland_array_pagination(count($myPages),5,'sida'))

分页数组的示例

  • 该数组包含所有分页所需的信息
array (size=13)
  'size' => int 5
  'current_page' => int 5
  'antal_items' => int 43
  'total_pages' => int 9
  'start_item' => int 20
  'end_item' => int 25
  'first_page' => int 1
  'prev_page' => int 4
  'next_page' => int 6
  'last_page' => int 9
  'start_number' => int 2
  'end_number' => int 8
  'start_end' => 
    array (size=7)
      0 => 
        array (size=1)
          'number' => int 2
      1 => 
        array (size=1)
          'number' => int 3
      2 => 
        array (size=1)
          'number' => int 4
      3 => 
        array (size=1)
          'number' => int 5
      4 => 
        array (size=1)
          'number' => int 6
      5 => 
        array (size=1)
          'number' => int 7
      6 => 
        array (size=1)
          'number' => int 8

遍历条目区间

  • 如果您不想每次都获取数组,则可以在会话中存储它
  • 请注意,您不会像通常那样遍历数组
  • 相反,您会遍历"数组的索引",并通过索引号调用值
@if(function_exists('get_region_halland_page_children'))
  @php($myPages = get_region_halland_page_children())
    @if(isset($myPages))
      @php($myPagination = get_region_halland_array_pagination(count($myPages),5,'sida'))
        @php($i = $myPagination['start_item'])
        <?php while ($i < $myPagination['end_item']) { ?>
          {{ $myPages[$i]['title'] }}<br>
          {{ $myPages[$i]['content'] }}<br>
        <?php $i++; } ?>
    @endif
@endif

显示条目总数和当前页码

Det finns {{ $myPagination['antal_items'] }} sidor
Du är på sida {{ $myPagination['current_page'] }} av {{ $myPagination['total_pages'] }}	

显示导航

<span><a href="./?sida={{ $myPagination['first_page'] }}"><<</a></span>
<span><a href="./?sida={{ $myPagination['prev_page'] }}"><</a></span>
  @foreach ($myPagination['start_end'] as $start_end)
    <span>
      @if($myPagination['current_page'] == $start_end['number'])
	    <strong>
	      <a href="./?sida={{ $start_end['number'] }}">{!! $start_end['number'] !!}</a>
	    </strong>
	  @else
	    <a href="./?sida={{ $start_end['number'] }}">{!! $start_end['number'] !!}</a>
	  @endif
	</span>
  @endforeach
<span><a href="./?sida={{ $myPagination['next_page'] }}">></a></span>
<span><a href="./?sida={{ $myPagination['last_page'] }}">>></a></span>

版本历史

1.4.0

  • 添加了通过Packagist发布管道
  • 调整了composer名称

1.3.0

  • 附加了许可证模型文件

1.2.0

  • 更新了README中的链接

1.1.0

  • 添加了有关许可证模型的信息

1.0.1

  • 在"end_item"中更正了最后一页的条目数

1.0.0

  • 第一个版本