So I'm doing this in PHP but it is a logic issue so I'll try to write it as generically as possible.
To start here's how this pagination script works:
- for (draw first three pages links)
- if (draw ellipsis (...) if there are pages between #1's pages and #3's pages)
- for (draw current page and two pages on each side of it links)
- if (draw elipsis (...) if there are pages between #3's pages and #5's pages)
- for (draw final three pages links)
The problem is that when there are low amounts of pages (I noticed this when the page count was at 10) there should be an ellipsis but none is drawn.
Onto the code:
$page_count = 10; //in actual code this is set properly
$current_page = 1; //in actual code this is set properly
for ($i = 1;$i <= 3;$i++)
{
if ($page_count >= $i)
echo $i;
}
if ($page_count > 3 && $current_page >= 7)
echo "...";
for ($i = $current_page - 2;$i <= current_page + 2;$i++)
{
if ($i > 3 && $i < $page_count - 2)
echo $i;
}
if ($page_count > 13 && $current_page < $page_count - 5)
echo "...";
for ($i = $page_count - 2;$i <= $page_count;$i++)
{
if ($page_count > 3)
echo $i;
}
So I figure the best idea would to be to modify one of the two ellipsis if statements to include a case like this, however I've tried and am stumped.
Also please note that I condensed this code for readability sake so please don't give tips like "those for loops are ineffective because they will recalculate current_page - 2 for each iteration" because I know :)
For those whom want to see a breakdown of how this logic currently works, here is example output ( modified ) with iterating $page_count and $current_page. http://rafb.net/p/TNa56h71.html