Jump to content

help with pagination display


scarhand

Recommended Posts

heres my code:

 

<?php

if ($pagi_count > 1)
{
	echo '<ul class="pagination">';
	echo '<li><a href="#">«</a></li>';

	$pagi_start = 1;
	$pagi_end = $pagi_count;

	for ($p = $pagi_start; $p <= $pagi_end; $p++)
	{
		$link = "$url/page/".$get_letter;

		if ($p > 1)
			$link .= "/$p";

		if ($p == $pagi_num)
			$class = ' class="current"';
		else
			$class = '';

		echo '<li'.$class.'><a href="'.$link.'">'.$p.'</a></li>';
	}

	echo '<li><a href="#">»</a></li>';
	echo '</ul>';
}

?>

 

now this works fine, however i want it to only show 20 page numbers, and if there are more than 20 total pages, i want the current page to be in the middle of the list (unless of course the current page is 1 or 2 then it would be more to the left of the list........

 

example:

 

with 13 total pages, on page 8:

<< 1 2 3 4 5 6 7 (8) 9 10 11 12 13 >>

 

with 55 total pages, on page 2:

<< 1 (2) 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 >>

 

with 65 total pages, on page 12:

<< 2 3 4 5 6 7 8 9 10 11 (12) 13 14 15 16 17 18 19 20 21 >>

 

im really stumped on the math for this....any help would be much appreciated.

Link to comment
Share on other sites

i got it

 

<?php

if ($pagi_count > 1)
{
	echo '<ul class="pagination">';

	if ($pagi_num > 1)
		echo "<li><a href=\"$url/page/$get_letter\">«</a></li>";

	$pagi_start = 1;
	$pagi_end = $pagi_count;

	if ($pagi_count > 15) 
	{
		$pagi_start = $pagi_num - 7;
		$pagi_end = $pagi_num + 7;

		if ($pagi_start < 1) 
		{
			$pagi_end -= $pagi_start;
			$pagi_start = 1;
		}

		if ($pagi_end > $pagi_count) 
		{
			 $pagi_start += ($pagi_count - $pagi_end);
			 $pagi_end = $pagi_count;
		}
	}

	for ($p = $pagi_start; $p <= $pagi_end; $p++)
	{
		$link = "$url/page/$get_letter";

		if ($p > 1)
			$link .= "/$p";

		if ($p == $pagi_num)
			$class = ' class="current"';
		else
			$class = '';

		echo '<li'.$class.'><a href="'.$link.'">'.$p.'</a></li>';
	}

	if ($pagi_num < $pagi_count)
		echo "<li><a href=\"$url/page/$get_letter/$pagi_count\">»</a></li>";

	echo '</ul>';
}

?>

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.