Home > other >  Php pagination with limited displayed pages
Php pagination with limited displayed pages

Time:02-10

I'm trying to do some pagination in PHP over an array. Everything works, my pagination gives me the right amount of pages. But my nav displays all the pages required in order to go at the end of the array, like this : enter image description here

I would like to define a limit of pages available in the nav, like only 5 pages. With the possibility for the nav to keep iterating, keeping those 5 links up, but going from page 1 to page 20. Can you help me pls ?

<nav>
        <ul >
            <li disabled" : "" ?>">
                <a href="./?page=<?= $currentPage - 1 ?>" >Previous</a>
            </li>

            <?php for ($pagesNumber = 1; $pagesNumber <= $pagesMax; $pagesNumber  ) : ?>
                <li active" : "" ?>">
                    <a href="./?page=<?= $pagesNumber ?>" ><?= $pagesNumber ?></a>
                </li>
            <?php endfor ?>

            <li disabled" : "" ?>">
                <a href="./?page=<?= $currentPage   1 ?>" >Next</a>
            </li>
        </ul>
    </nav>

CodePudding user response:

  •  Tags:  
  • Related