Fixed pagination when no pages should be shown
This commit is contained in:
parent
b5581c5822
commit
4d260b6fe5
1 changed files with 42 additions and 40 deletions
|
@ -31,49 +31,51 @@ if (!function_exists('pageUrl'))
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<nav class="paginator-wrapper">
|
<?php
|
||||||
<ul class="paginator">
|
$pagesVisible = [];
|
||||||
<?php if ($this->context->transport->page > 1): ?>
|
$pagesVisible []= 1;
|
||||||
<li class="prev">
|
$pagesVisible []= $this->context->transport->pageCount;
|
||||||
<?php else: ?>
|
$delta = 3;
|
||||||
<li class="prev inactive">
|
$pagesVisible = array_merge($pagesVisible, range($this->context->transport->page - $delta, $this->context->transport->page + $delta));
|
||||||
<?php endif ?>
|
$pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->pageCount; });
|
||||||
<a href="<?php echo pageUrl($this->context->transport->page - 1) ?>">
|
$pagesVisible = array_unique($pagesVisible);
|
||||||
«
|
sort($pagesVisible, SORT_NUMERIC);
|
||||||
</a>
|
?>
|
||||||
</li>
|
|
||||||
|
|
||||||
<?php
|
<?php if (!empty($pagesVisible)): ?>
|
||||||
$pagesVisible = [];
|
<nav class="paginator-wrapper">
|
||||||
$pagesVisible []= 1;
|
<ul class="paginator">
|
||||||
$pagesVisible []= $this->context->transport->pageCount;
|
<?php if ($this->context->transport->page > 1): ?>
|
||||||
$delta = 3;
|
<li class="prev">
|
||||||
$pagesVisible = array_merge($pagesVisible, range($this->context->transport->page - $delta, $this->context->transport->page + $delta));
|
|
||||||
$pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->pageCount; });
|
|
||||||
$pagesVisible = array_unique($pagesVisible);
|
|
||||||
sort($pagesVisible, SORT_NUMERIC);
|
|
||||||
?>
|
|
||||||
|
|
||||||
<?php foreach ($pagesVisible as $page): ?>
|
|
||||||
<?php if ($page == $this->context->transport->page): ?>
|
|
||||||
<li class="active">
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<li>
|
<li class="prev inactive">
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<a href="<?php echo pageUrl($page) ?>">
|
<a href="<?php echo pageUrl($this->context->transport->page - 1) ?>">
|
||||||
<?php echo $page ?>
|
«
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach ?>
|
|
||||||
|
|
||||||
<?php if ($this->context->transport->page < $this->context->transport->pageCount): ?>
|
<?php foreach ($pagesVisible as $page): ?>
|
||||||
<li class="next">
|
<?php if ($page == $this->context->transport->page): ?>
|
||||||
<?php else: ?>
|
<li class="active">
|
||||||
<li class="next inactive">
|
<?php else: ?>
|
||||||
<?php endif ?>
|
<li>
|
||||||
<a href="<?php echo pageUrl($this->context->transport->page + 1) ?>">
|
<?php endif ?>
|
||||||
»
|
<a href="<?php echo pageUrl($page) ?>">
|
||||||
</a>
|
<?php echo $page ?>
|
||||||
</li>
|
</a>
|
||||||
</ul>
|
</li>
|
||||||
</nav>
|
<?php endforeach ?>
|
||||||
|
|
||||||
|
<?php if ($this->context->transport->page < $this->context->transport->pageCount): ?>
|
||||||
|
<li class="next">
|
||||||
|
<?php else: ?>
|
||||||
|
<li class="next inactive">
|
||||||
|
<?php endif ?>
|
||||||
|
<a href="<?php echo pageUrl($this->context->transport->page + 1) ?>">
|
||||||
|
»
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<?php endif ?>
|
||||||
|
|
Reference in a new issue