Good morning! I would like some help to limit the amount of links and display in pagination. My links are displayed like this:
Previous 1 2 3 4 5 Next
As the number of links does not get too large, I'd like it to look like this:
Previous 1 2 ... Next
Previous ... 3 4 5 ... Next
Previous ... 6 7 Next
My php + bootstrap code:
$pagina = (isset($_GET['pagina'])) ? (int)$_GET['pagina'] : 1;
$sql_pagina = "SELECT * FROM posts";
$result_pagina = $conexao->prepare($sql_pagina);
$result_pagina->execute();
$numTotal = $result_pagina->rowCount();
$quantidade = 5;
$num_pagina = ceil($numTotal/$quantidade);
$inicio = ($pagina * $quantidade) - $quantidade;
...
código HMTL
...
<?php
$pagina_anterior = $pagina -1;
$pagina_posterior = $pagina + 1;
?>
<nav align="center" aria-label="Page navigation" class="nav-pagination" style="margin-bottom: 20px;">
<ul class="pagination">
<li>
<?php
if($pagina_anterior != 0) { ?>
<a href="http://www.arturluz.com/?pagina=<?php echo $pagina_anterior; ?>" aria-label="Previous">
<span aria-hidden="true">Anterior</span>
</a>
<?php } else { ?>
<span aria-hidden="true">Anterior</span>
<?php } ?>
</li>
<?php
for($i = 1; $i < $num_pagina + 1; $i++){ ?>
<li><a href="http://www.arturluz.com/?pagina=<?php echo $i; ?>"><?php echo $i; ?></a></li>
<?php } ?>
<li>
<?php
if($pagina_posterior <= $num_pagina) { ?>
<a href="http://www.arturluz.com/?pagina=<?php echo $pagina_posterior; ?>" aria-label="Previous">
<span aria-hidden="true">Próximo</span>
</a>
<?php } else { ?>
<span aria-hidden="true">Próximo</span>
<?php } ?>
</li>
</ul>
</nav>
Can anyone help me? Thanks!