Created
July 18, 2011 17:22
-
-
Save raelmax/1090095 to your computer and use it in GitHub Desktop.
With this codesnippet your pagination don't show all page links, only two next pages and two previous pages, don't creating monstrous list of pages! :)
This file contains hidden or 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 is_paginated %} | |
<nav id="pagination"> | |
{% if page_obj.has_previous %} | |
<a href="?page={{ page_obj.previous_page_number }}">previous page</a> | |
{% endif %} | |
{% for page in page_obj.paginator.page_range %} | |
{% if page >= page_obj.number|add:"-2" and page < page_obj.number %} | |
<a href="?page={{ page }}">{{ page }}</a> | |
{% endif %} | |
{% ifequal page_obj.number page %} | |
<span>{{ page_obj.number }}</span> | |
{% endifequal %} | |
{% if page <= page_obj.number|add:"2" and page > page_obj.number %} | |
<a href="?page={{ page }}">{{ page }}</a> | |
{% endif %} | |
{% endfor %} | |
{% if page_obj.has_next %} | |
<a href="?page={{ page_obj.next_page_number }}">next page</a> | |
{% endif %} | |
</nav> | |
{% endif %} |
This is the django template language. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What the language are you using in this code snippet? This is Python or a template engine?