Skip to content

Simple and easy to use plugin for website to paginate pages or whatever you want.

License

Notifications You must be signed in to change notification settings

Matmaus/Paginator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple Paginator - BETA

Simple and easy to use plugin for websites to paginate of pages or whatever you want.

Features

  • Easy to use
  • Multi-language support - EN, SK, CZ are predefined, possibility to add new one
  • More editable CSS styles

Install

  1. Download manually Paginator plugin. Store Paginator file wherever you want.
  2. Include this file everywhere you wish to use Paginator.
  3. 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.
  4. Set new state by calling setStatePaginateArrows or setStatePaginateNumbers methods.
  5. Call method to print HTML code.

Configure

Creating of instances
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);

Use

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:

getLimit()

Getter for limit

Return

Limit

getOffset()

Getter for offset

Return

Offset

getMobile()

Get generated HTML code of mobile version

Return

<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>

getNormal()

Get generated HTML code of normal version

Return

<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>

getNormalAndMobile()

Get generated HTML code for both versions, mobile and normal

Return

<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>

printNormalAndMobile()

Print generated HTML code for both versions, mobile and normal

setStatePaginateArrows()

Set new state for arrow style. This means to set new limit, offset, url pattern, table, ... Any method described above works with actual state.

Parameters

Full URL address with index of page replaced by (:num)

Example of usable UrlPatterns
$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

setStatePaginateNumbers()

Set new state for numeric style. This means to set new limit, offset, url pattern, table, ... Any method described above works with actual state.

Parameters

Full URL address with index of page replaced by (:num)

Example of usable UrlPatterns
$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

addLanguage()

Add new language

Parameters

Array or object containing new language

Example

$myVeryOwnLanguage = [
			"page"       => "Page",
			"of"         => "of",
			"next_page"  => "Next page",
			"prev_page"  => "Previous page",
			"first_page" => "First page",
			"last_page"  => "Last page"
		];
$paginator->addLanguage($myVeryOwnLanguage);

License

The MIT License (MIT). Please see License File for more information.

About

Simple and easy to use plugin for website to paginate pages or whatever you want.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages