Jump to content

if ($pages < $page - 3 || $pages > $page + 3) return;


jirimail

Recommended Posts

Hope someone could help, should be easy  ;)

 

I have this code to limit number of  shown pages for my pagination, but it doesnt work. Any other ideas how to set condiditin AND codition?? As in this code:

if ($pages < $page - 3 || $pages > $page + 3) return;

 

The whole script is: should work, but it doest, going mad from it  ???

function page($url) {
	global $page;
	$pages=1;
	for ($starter=0; $this->total>$starter; $starter+=$this->limit) {
		if ($pages != $page)
			echo "<a href=\"".$url.$pages."\" class=\"page\">$pages</a> \n";
		else
			echo "<b>[ $pages ]</b> \n";
	$pages++;
                if ($pages < $page - 3 || $pages > $page + 3) return;
                             }
                }

Link to comment
Share on other sites

basically... continue; tells the for() to stop what its doing, and start the loop over again... which, in this case, should cut off either end of the numbers...

function page($url) {
global $page;
$pages=1;
for($starter=0; $this->total>$starter; $starter+=$this->limit) {
  if ($pages < $page-3 && $pages > $page+3) continue;
  if ($pages != $page) echo "<a href=\"".$url.$pages."\" class=\"page\">$pages</a> \n";
  else echo "<b>[ $pages ]</b> \n";
  $pages++;
}
}

Link to comment
Share on other sites

Ok, i think i start understanding  :)

The thing is that this first script shows all the pages

function page($url) {
	global $page;
	$pages=1;
	for ($starter=0; $this->total>$starter; $starter+=$this->limit) {
		if ($pages != $page)
			echo "<a href=\"".$url.$pages."\" class=\"page\">$pages</a> \n";
		else
			echo "<b>[ $pages ]</b> \n";
	$pages++;
	}
}

 

And than i though, if i add this code that should cut off the rest of the pages and shows etc: 5 6 7 [8] 9 10 11

 

if ($pages < $page - 3 && $pages > $page + 3) return;

 

but it still goes:      1 2 3 4 5 ...65 [66] 67 68

still not taking care of the first pages..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.