Skip to content

Instantly share code, notes, and snippets.

@RobertMatkulcik
Created November 27, 2022 22:05
Show Gist options
  • Save RobertMatkulcik/e9b836c7a5681ea5646a7c524f092bfd to your computer and use it in GitHub Desktop.
Save RobertMatkulcik/e9b836c7a5681ea5646a7c524f092bfd to your computer and use it in GitHub Desktop.
*/
public function showPagination() {
// Custom rewriting of style. Can be turned off by disabling the variable or customized using variables.
if($this->overwriteStyle) {
echo "
<style>
ul.pagination li a{
background-color: $this->styleColorBg;
color: $this->styleColorText;
border-color: $this->styleColorBorder;
}
ul.pagination li a:hover{
background-color: $this->styleColorBgHover;
color: $this->styleColorTextHover;
border-color: $this->styleColorBorderHover;
}
ul.pagination li.active a{
background-color: $this->styleColorBgActive;
color: $this->styleColorTextActive;
border-color: $this->styleColorBorderActive;
font-weight: bold;
}
ul.pagination li.active a:hover{
background-color: $this->styleColorBgActive;
color: $this->styleColorTextActive;
border-color: $this->styleColorBorderActive;
}
ul.pagination li a.pagination-dots:hover {
background-color: $this->styleColorBg;
color: $this->styleColorText;
border-color: $this->styleColorBorder;
cursor: default;
}
ul.pagination li.disabled a {
color: #BBB;
border-color: #DDD;
}
ul.pagination li.disabled a:hover {
cursor: default;
color: #BBB;
}
</style>
";
}
echo '
<div style="text-align: center; width: 100%;">
<ul class="pagination">';
// arrow left
$disabled = (($this->activePage <= 1) ? TRUE : FALSE);
echo ' <li class="'.($disabled ? 'disabled' : NULL).'">
<a '.($disabled ? NULL : 'href="'.$this->pageNumberLink('prev').'"'). ' aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>';
// numbers
if($this->totalPages > $this->useDotsLimit) {
// displaying limited pagination
$displayedDots = FALSE;
for($i = 1; $i<=$this->totalPages; $i++) {
if(
($i <= 2)
OR
($i >= $this->totalPages-1)
OR
(abs($i-$this->activePage) < 3)
) {
$displayedDots = FALSE;
echo '
<li class="'.($i == $this->activePage ? 'active' : NULL).'">
<a href="'.$this->pageNumberLink($i).'" >
'.$i.'
</a>
</li>';
}
else if(!$displayedDots) {
$displayedDots = TRUE;
echo '
<li class="'.($i == $this->activePage ? 'active' : NULL).'">
<a class="pagination-dots">...</a>
</li>';
}
}
}
else {
// displaying normal pagination - less than 10 pages
for($i = 1; $i<=$this->totalPages; $i++) {
echo '
<li class="' . ($i == $this->activePage ? 'active' : NULL) . '">
<a href="' . $this->pageNumberLink($i) . '" >
' . $i . '
</a>
</li>';
}
}
// arrow right
$disabled = ($this->activePage >= ($this->totalPages) ? TRUE : FALSE);
echo ' <li class="'.($disabled ? 'disabled' : NULL).'">
<a '.($disabled ? NULL : 'href="'.$this->pageNumberLink('next').'"').' aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>';
echo '
</ul>
</div>';
// output META
$this->metaPagination();
$this->errorsAndRedirects();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment