Jump to content

Recommended Posts

Hi all,

 

I've searched hi an low for this but can't find it anywhere.

 

I've got pagination working no problem but what I want to be able to do is to break the pages down in to chunks. If there is 200 pages then showing links to all 200 is not good.

 

So what I am trying to do is split the pages in to chunks (5 or 10 etc then adding >> or <<)

 

So if I'm currently on page 8 and my chunks are set to 10 and there are 200 pages the pagination would look like this:

 

1 2 3 4 5 6 7 8 9 10>> (clicking >> would take you to <<11 12 13...20>> etc).

 

My pagination currently looks like this:

<?php
//set intial vars
$total_pages=21;
$chunks=5;
$current_page=$_GET[goto];

if($current_page==""){$current_page=1;}
//set the from and to
//from

//I'm stuck here!!

for($p=1;$p<=$total_pages;$p++){
if($p==$current_page){
	echo "<b>$p</b> ";
}else{
	echo "<a href=\"".$_SERVER['PHP_SELF']."?goto=$p\">$p</a> ";
}
}
?>

I've tried 101 ways of doing this but keep failing!

 

Anyone help out?

thanks

 

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

Instead of having your page link creation loop count from 1 to $total_pages, have it count from a range, relative to the current page.

 

$range = 5; // number of pages to have before current and after current

for ($p = ($current_page - $range); $p <= ($current_page + $range); $p++) {
...
}

 

You are going to have to put a condition inside that loop to check if $p is below or above the min or max, of course.  If it is, then don't display the link, so it creates

 

1 2 3 4 5 6 7 8 9

 

instead of

 

-1 0 1 2 3 4 5 6 7 8 9

 

 

As far as the << and >> part: You would add a condition to check if your << marker isn't below or above min or max page. If it's not, you display it.  The << would go before the loop, the >> after the loop. 

 

 

Link to comment
https://forums.phpfreaks.com/topic/107082-more-pagination/#findComment-548971
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.