Jump to content

Pagination


loganbest

Recommended Posts

I wrote a pagination script but it displays EVERY page in a block. I'm trying to get it to display only the current page # +/- 5 page numbers.

 

for ($i=0; $i < $this->totalPages; $i++) {
				$pagesEndCount = $i + 1;
				if(($i-10) < $this->currentPage || $i >= $this->currentPage) {
				if($i != $this->currentPage) {
					printf('<a href="'."%s?$this->pagingURL=%d%s", $this->thisPage, $i, $pagingURL .'">'.$pagesEndCount."</a>");
				}else{
					echo("$this->beforeCurrentPage$pagesEndCount$this->afterCurrentPage");
				}

				if($i != $this->totalPages-1) echo($this->linkDelimiter);
				}

Link to comment
https://forums.phpfreaks.com/topic/208050-pagination/
Share on other sites

The starting number would be:

 max($this->currentPage-5, 0);

The ending page number would be:

min($this->currentPage+5, $this->totalPages)

so you can change your loop:

 

$start =  max($this->currentPage-5, 0);
$end = min($this->currentPage+5, $this->totalPages);
for ($i=$min; $i < $max; $i++) {
if($i != $this->currentPage) {
	...
}else{
	...
}
}

Link to comment
https://forums.phpfreaks.com/topic/208050-pagination/#findComment-1087610
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.