Simple and easy to use plugin for websites to paginate of pages or whatever you want.
- Easy to use
- Multi-language support - EN, SK, CZ are predefined, possibility to add new one
- More editable CSS styles
- Download manually Paginator plugin. Store Paginator file wherever you want.
- Include this file everywhere you wish to use Paginator.
- Create objects, as many as you wish.
DO NOT FORGET about using namespace Matmaus. If you want to use only single database and single language, you need just to create one instance, even if you want to paginate more items on a single page. - Set new state by calling
setStatePaginateArrows
orsetStatePaginateNumbers
methods. - Call method to print HTML code.
Parameter | Explaining |
---|---|
database | PDO |
language | must be one of predefined ("en", "sk", "cz") even if using own language, "en" is set as default |
limit | positive number, used as default limit when is not specified by called method, default is set to 5 |
Example:
$paginator = new Paginator($database);
OR
$paginator = new Paginator($database, "en", 5);
After creating a new instance, everything you need is to call methods on your objects.
Example:
<?php require_once 'Paginator.php'; ?>
...
<?php
$paginator->setStatePaginateArrows("http://localhost/notices/(:num)", "notices", $offset);
$results = get_notices( $paginator->getOffset(), $paginator->getLimit() );
?>
...
<?php if ( count($results) ) :foreach ( $results as $notice ) : $notice = format_notice( $notice )?>
<article id="notice_<?= $notices->id ?>" class="notice">
<h2>
<a href=" <?= $notice->link ?> ">
<?= $notice->title ?>
</a>
</h2>
<div class="notice_content">
<?= $notice->teaser ?>
</div>
<time datetime="<?=$notice->created_at?>">
<small>
Created: <?=$notice->created_at;?>
</small>
</time>
<time datetime="<?=$notice->updated_at?>">
<small>
Updated: <?=$notice->updated_at?>
</small>
</time>
<span class="read_more">
<a href=" <?= $notice->link ?> ">See more</a>
</span>
</article>
<?php endforeach; endif; ?>
<?php $paginator->printNormalAndMobile(); ?>
...
Here are methods you can call:
Getter for limit
Limit
Getter for offset
Offset
Get generated HTML code of mobile version
<div class="mob_paging">
<p>
<a href="http://localhost/farnost/example/1" title="First page"><i class="fa fa-angle-double-left"></i></a>
<a href="http://localhost/farnost/example/1" title="Previous page"><i class="fa fa-angle-left"></i></a>
<span class="disabled"><i class="fa fa-angle-right"></i></span>
<span class="disabled"><i class="fa fa-angle-double-right"></i></span>
</p>
</div>
Get generated HTML code of normal version
<div class="paging">
<p>
<a href="http://localhost/farnost/example/1" title="First page"><i class="fa fa-angle-double-left"></i></a>
<a href="http://localhost/farnost/example/1" title="Previous page"><i class="fa fa-angle-left"></i></a>
Page 2 of 2, 9 - 14 / 14
<span class="disabled"><i class="fa fa-angle-right"></i></span>
<span class="disabled"><i class="fa fa-angle-double-right"></i></span>
</p>
</div>
Get generated HTML code for both versions, mobile and normal
<div class="paging">
<p>
<a href="http://localhost/farnost/example/1" title="First page"><i class="fa fa-angle-double-left"></i></a>
<a href="http://localhost/farnost/example/1" title="Previous page"><i class="fa fa-angle-left"></i></a>
Page 2 of 2, 9 - 14 / 14
<span class="disabled"><i class="fa fa-angle-right"></i></span>
<span class="disabled"><i class="fa fa-angle-double-right"></i></span>
</p>
</div>
<div class="mob_paging">
<p>
<a href="http://localhost/farnost/example/1" title="First page"><i class="fa fa-angle-double-left"></i></a>
<a href="http://localhost/farnost/example/1" title="Previous page"><i class="fa fa-angle-left"></i></a>
<span class="disabled"><i class="fa fa-angle-right"></i></span>
<span class="disabled"><i class="fa fa-angle-double-right"></i></span>
</p>
</div>
Print generated HTML code for both versions, mobile and normal
Set new state for arrow style. This means to set new limit, offset, url pattern, table, ... Any method described above works with actual state.
Full URL address with index of page replaced by (:num)
$urlPattern = 'http://localhost/foo/articles/(:num)/slug';
$urlPattern = 'http://localhost/foo/articles/items/(:num)';
$urlPattern = 'http://localhost/foo/page/(:num)';
$urlPattern = 'http://localhost/foo?page=(:num)';
Name of table Offset Limit
Set new state for numeric style. This means to set new limit, offset, url pattern, table, ... Any method described above works with actual state.
Full URL address with index of page replaced by (:num)
$urlPattern = 'http://localhost/foo/articles/(:num)/slug';
$urlPattern = 'http://localhost/foo/articles/items/(:num)';
$urlPattern = 'http://localhost/foo/page/(:num)';
$urlPattern = 'http://localhost/foo?page=(:num)';
Name of table Offset Limit
Add new language
Array or object containing new language
$myVeryOwnLanguage = [
"page" => "Page",
"of" => "of",
"next_page" => "Next page",
"prev_page" => "Previous page",
"first_page" => "First page",
"last_page" => "Last page"
];
$paginator->addLanguage($myVeryOwnLanguage);
The MIT License (MIT). Please see License File for more information.