Jump to content

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
https://forums.phpfreaks.com/topic/200710-pages/
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
https://forums.phpfreaks.com/topic/200710-pages/#findComment-1053252
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
https://forums.phpfreaks.com/topic/200710-pages/#findComment-1053405
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.