1
Good morning! I would like a help to limit the amount of links and be displayed in the pagination. My links are displayed like this:
Previous 1 2 3 4 5 6 7 Next
For the number of links not getting too large, I’d like it to stay that way:
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? Thank you!
Hello Andrei! I made the switch but the display looked something like this: Previous 1 2 Next ... Previous 1 2 3 Next ... Previous 2 3 4 Next ... Previous 3 4 Next ... . The three dots got off the bootstrap Nav.
– Rodrigo Souza Jesus
@Rodrigosouzajesus I will check
– Andrei Coelho
@Rodrigosouzajesus check if your code matches the one I edited
– Andrei Coelho
put a
<span>
in the 3 dots– Andrei Coelho
worked perfectly. As it is good to have help from people like you, thank you! Here is the result on the link http://www.arturluz.com/.
– Rodrigo Souza Jesus
do you understand about url friendly? if yes, can send me your email?
– Rodrigo Souza Jesus