1
0
Fork 0

Fix pagination

This commit is contained in:
Ethanell 2021-01-16 18:31:17 +01:00
parent 513d5ff4d4
commit c2a468c66d
2 changed files with 3 additions and 3 deletions

View file

@ -20,7 +20,7 @@ class HomeController extends AbstractController
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
'posts' => $repo->getPublished($page*5, 5),
'pages' => round(count($repo->getPublished())/5, 0, PHP_ROUND_HALF_UP),
'pages' => round(count($repo->getPublished())/5, 0, PHP_ROUND_HALF_UP)-1,
'page' => $page
]);
}

View file

@ -19,11 +19,11 @@
<nav aria-label="Post navigation">
<ul class="pagination justify-content-center">
<li class="page-item {{ page <= 0 ? "disabled" : "" }}"><a class="page-link" href="{{ path('home', {'page': page-1}) }}">Previous</a></li>
{% for p in 0..pages %}
{% for p in 0..pages+1 %}
{% set active = p == page %}
<li class="page-item {{ active ? 'active' : '' }} {{ active ? '' : 'aria-current="page"' }}"><a class="page-link" href="{{ path('home', {'page': p}) }}">{{ p }} {{ active ? '<span class="visually-hidden">(current)</span>' : '' }}</a></li>
{% endfor %}
<li class="page-item {{ page >= pages ? "disabled" : "" }}"><a class="page-link" href="{{ path('home', {'page': page+1}) }}">Next</a></li>
<li class="page-item {{ page > pages ? "disabled" : "" }}"><a class="page-link" href="{{ path('home', {'page': page+1}) }}">Next</a></li>
</ul>
</nav>
{% endblock %}