Add pagination to blog posts

Implemented pagination in the blog to display 3 posts per page.
This change allows users to navigate through posts using a
pagination control at the bottom of the page. The pagination
follows the pattern: << < 1 2 3 ... n > >>, enabling navigation
to the first, previous, specific, next, or last pages. This
improves user experience by preventing long scrolls on pages
with many posts.

Issue ID: FLAS-33
This commit is contained in:
Neo 2024-09-09 23:07:10 +00:00 committed by Jose Palazon
parent 3b04a2b18b
commit 8e63ba89db
2 changed files with 29 additions and 1 deletions

View file

@ -25,5 +25,24 @@
<hr>
{% endif %}
{% endfor %}
<div class="pagination">
{% if page > 1 %}
<a href="{{ url_for('blog.index', page=1) }}"><<</a>
<a href="{{ url_for('blog.index', page=page-1) }}"><</a>
{% endif %}
{% for p in range(1, total_pages + 1) %}
{% if p == page %}
<strong>{{ p }}</strong>
{% else %}
<a href="{{ url_for('blog.index', page=p) }}">{{ p }}</a>
{% endif %}
{% endfor %}
{% if page < total_pages %}
<a href="{{ url_for('blog.index', page=page+1) }}">></a>
<a href="{{ url_for('blog.index', page=total_pages) }}">>></a>
{% endif %}
</div>
<script src="{{ url_for('static', filename='collapse.js') }}"></script>
{% endblock %}