Created
September 2, 2012 15:45
-
-
Save ndarville/3600717 to your computer and use it in GitHub Desktop.
Django Pagination Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if page.has_other_pages %} | |
<div class="pagination"> | |
<!-- Older page --> | |
{% if page.has_previous %} | |
<a href="?page={{ page.previous_page_number }}" title="Go to the older threads.">< Older</a> | |
{% endif %} | |
<!-- First page --> | |
{% if current_page > 4 %} | |
<a href="?page=1">1</a> ⋯ | |
{% endif %} | |
<!-- Current page -3 --> | |
{% if current_page > 3 %} | |
<a href="?page={{ current_page|add:"-3" }}">{{ current_page|add:"-3" }}</a> | |
{% endif %} | |
<!-- Current page -2 --> | |
{% if current_page > 2 %} | |
<a href="?page={{ current_page|add:"-2" }}">{{ current_page|add:"-2" }}</a> | |
{% endif %} | |
<!-- Current page -1 --> | |
<!-- current_page > 1 --> | |
{% if page.has_previous %} | |
<a href="?page={{ page.previous_page_number }}">{{ current_page|add:"-1" }}</a> | |
{% endif %} | |
<!-- Current page --> | |
{{ current_page }} | |
<!-- Current page +1 --> | |
<!-- current_page < total_pages --> | |
{% if page.has_next %} | |
<a href="?page={{ page.next_page_number }}">{{ current_page|add:"1" }}</a> | |
{% endif %} | |
<!-- Current page +2 --> | |
{% if current_page < total_pages|add:"-1" and total_pages > 2 %} | |
<a href="?page={{ current_page|add:"2" }}">{{ current_page|add:"2" }}</a> | |
{% endif %} | |
<!-- Current page +3 --> | |
{% if current_page < total_pages|add:"-2" %} | |
<a href="?page={{ current_page|add:"3" }}">{{ current_page|add:"3" }}</a> | |
{% endif %} | |
<!-- Last page --> | |
{% if current_page < total_pages|add:"-3" and total_pages > 4 %} | |
⋯ <a href="?page={{ total_pages }}">{{ total_pages }}</a> | |
{% endif %} | |
<!-- Newer page --> | |
{% if page.has_next %} | |
<a href="?page={{ page.next_page_number }}" title="Go to the newer threads.">Newer ></a> | |
{% endif %} | |
</div> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To see a working example, check out my
pony-forum
repo.