Jump to content

Pages...


EsOne

Recommended Posts

I currently use the following script to make links from page to page on my website.

<?php
echo "<p id=\"pages\">";
for($i=0;$i<$limit;$i+=15){
echo "| <a href=\"?start=".($i+1)."\">".($i/15+1)."</a> | ";
}
?>

 

Now, I am getting so many pages, that management of them is getting difficult.

 

I want to make it where it only shows the previous 5 pages to the current, and the next 5 pages fromt he current.

So, if a person was on page 10, It would show  ...5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15...

 

Keep in mind I am pretty code dumb, as I am just learning. So any help would have to be dumbed down pretty good.

 

To see what links I am talking about in person, the website is: http://dolphinmania.pandaandpenguin.com/dolphinmania

 

 

Link to comment
Share on other sites

<?php

$current_page = 9;

$span_pages = 5;
$start_page = (($current_page-5) < 1) ? 1 : ($current_page-5);
$end_page   = (($current_page+5) > $limit) ? $limit : ($current_page+5);

for($page=$start_page; $page<=$end_page; $page++)
{
    if($page==$current_page)
    {
        echo "| <b>{{$page}}</b> | ";
    }
    else
    {
        echo "| <a href=\"?start={$page}\">{$page}</a> | ";
    }
}

?>

Link to comment
Share on other sites

Thanks. Don't quite work though. With the start= section, each page starts every 15. So, page 2 would be start=16, page 3 would be start=31

 

That script assumes pages go as start=1 for page 1, and start=2 for page 2.

 

 

Link to comment
Share on other sites

I need it to do what this forums pages does. Exactly that

 

That is not what you requested. You stated you wanted to show the 5 pages before and the 5 pages after the current page. I only hard coded the current page for illustrative purposes. It is your responsibility to define the current page, the max pages (i.e. limit) and the span (which you already stated would be 5, but the code will allow for different values if you wish.

 

This foum uses more complex functionality to include, possibly, the very first and very last pages and ellipses as needed. You did not ask for that, so I did not provide it.

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.