Reputation: 90
I am trying to create a sitemap that a user can use to see the Hierarchy of the site, child pages and parent pages etc but I can't seem to find a way of showing this. Is there an app I can use or will I need to write a custom function?
Upvotes: 1
Views: 903
Reputation: 11228
You can get published pages like this:
Page.objects.live()
The default order is by path. Use the depth
field (a number) and some css to create hierarchy.
You can add context to your page like this:
class SitemapPage(Page):
...
def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
context.update({'pages': Page.objects.live()})
return context
And in your template:
{% for obj in pages %}
<a href="{% pageurl obj %}" class="level-{{ obj.depth }}">{{ obj.title }}</a>
{% endfor %}
Upvotes: 2