The first round of site updates are done. I didn't go with the infinite scroll, I got lazy and used the old tried-and-true Paginator I wrote well over a decade ago. It has been updated with baked-in bootstrap pagination classes. If you're interested, here's the code:
class Paginator
{
public $current_page = 1;
public $total_pages = 1;
public $total_records = 0;
public $display_total_only = 0;
public $query_string = 0;
public $singular_record_text = "";
public $plural_record_text = "";
private $inc = 1; // inc = increment by N page - used in prev/next
private $fp = 1; // fp = first page
public $threshold = 1; // th = threshold (keep pages visible +/- from current)
public $end_threshold = 1; // st = starter threshold - keep first page visible up to Nth page.
public function __construct($thispage=1,$totalpages=1,$totalrecords=0,$singular_text="record",$plural_text="records",$query_string=0)
{
$this->current_page = $thispage;
$this->total_pages = $totalpages;
$this->total_records = $totalrecords;
$this->singular_record_text = $singular_text;
$this->plural_record_text = $plural_text;
$this->query_string = $query_string;
}
public function getFirst()
{
return $this->fp;
}
public function getLast()
{
return $this->total_pages;
}
public function getPrev()
{
if (($this->current_page - $this->inc) >= $this->fp)
{
if ($this->current_page - $this->inc > $this->total_pages)
{
return $this->total_pages;
} else {
return $this->current_page - $this->inc;
}
} else {
return $this->fp;
}
}
public function getNext()
{
if (($this->current_page + $this->inc) > $this->total_pages)
{
return $this->total_pages;
} else {
return $this->current_page + $this->inc;
}
}
public function getMin()
{
if ($this->current_page <= $this->end_threshold)
{
return $this->fp;
} else {
return $this->current_page - $this->threshold;
}
}
public function getMax()
{
if ($this->total_pages <= $this->end_threshold) {
$max = $this->total_pages;
} else {
// if ($this->current_page < $this->end_threshold) { // commented out mb 090616
// $max = $this->end_threshold;
//} else {
if ($this->current_page > ($this->total_pages - $this->threshold)) {
$max = $this->total_pages;
} else {
if ($this->total_pages - $this->current_page == $this->threshold+1)
{
$max = $this->current_page + $this->threshold+1;
} else {
$max = $this->current_page + $this->threshold;
}
}
// }
}
return $max;
}
public function getNextBreak()
{
return ($this->getMax() < $this->total_pages)?1:0;
}
public function getPrevBreak()
{
return ($this->getMin() > 1)?1:0;
}
public function getPageLink($page)
{
return "/".$this->query_string . "/page/" . $page;
// return ($this->query_string?$this->query_string."&":"?")."page=" . $page;
}
public function getHTML()
{
$previouspage = $this->getPrev();
$currentpage = $this->current_page;
$nextpage = $this->getNext();
$firstpage = $this->getFirst();
$min = $this->getMin();
$max = $this->getMax();
$shownextbreak = $this->getNextBreak();
$showprevbreak = $this->getPrevBreak();
$html = '';
$html .= "<div class=\"text-center\">\n";
if ($this->display_total_only != 1)
{
$html .= "<ul class=\"pagination justify-content-center\">\n";
// first page link - mb 100723
if ($this->current_page != $this->getFirst() && $min > $this->getFirst() && $this->threshold != 0)
$html .= "<li class='page-item'><a class='page-link' href=\"" . $this->getPageLink($this->getFirst()) . "\">«</a></li>\n";
if ($this->current_page != $this->getFirst())
$html .= "<li class='page-item'><a class='page-link' href=\"" . $this->getPageLink($previouspage) . "\">‹</a></li>\n";
for ($i=$min;$i<=$max;$i++)
{
if ($this->current_page == $i)
{
$html .= "<li class='page-item active'><a class='page-link' href=\"" . $this->getPageLink($currentpage) . "\">" . //"<span".($this->threshold==0?"":" class=\"This-page\"").">".
($this->threshold==0?"Page ":"").$this->current_page.
($this->threshold==0?" of ".$this->total_pages:"").
"</a></li>\n";
} else {
if ($this->threshold!=0) $html .= "<li class='page-item'><a class='page-link' href=\"" . $this->getPageLink($i) . "\">$i</a></li>\n";
}
}
if ($this->current_page != $this->total_pages && $this->current_page < $this->total_pages)
$html .= "<li class='page-item'><a class='page-link' href=\"" . $this->getPageLink($nextpage) . "\">›</a></li>\n";
// last page link - mb 100723
if ($this->current_page != $this->getLast() && $max < $this->getLast() && $this->threshold != 0)
$html .= "<li class='page-item'><a class='page-link' href=\"" . $this->getPageLink($this->getLast()) . "\">»</a></li>\n";
$html .= "</ul>\n";
}
if ($this->total_records)
{
$html .= "<div class='Results'>" .
number_format($this->total_records) . " " .
($this->total_records <> 1?$this->plural_record_text:$this->singular_record_text) .
"</div>\n";
}
$html .= "</div>\n";
return $html;
}
} // end of class
Here's how it's used with a Smarty template:
if ( $total_pages > 1) {
$pagin = new Paginator($current_page,$total_pages);
$smarty->assign("paginator",$pagin->getHTML());
}