Django sitemaps with paginated content
Asked Answered
R

1

5

I don't think this is actually possible, but is there any clean and tidy way to get paginated content working with Django sitemaps?

For example, my landing page has news on it, and there are no permalinks to news posts, the only way to use them is to paginate 5 at a time through them all.

Another part gets lists of items in various genres and other criteria.

If it isn't possible, what is the best way to handle it? To not provide urls to the sitemap for any of these? To get just the first page for paginated pages?

My best idea is that I should just give the landing page as an url, and not bother with the listing pages at all since they aren't really important search engine-wise. But if this is the best course of action, how can I just provide a link to the landing page from within the sitemaps framework?

Any suggestions are welcome.

Reverberatory answered 9/9, 2011 at 3:52 Comment(2)
The question doesn't really identify a problem. Can you post some code? You appreciate that sitemaps is not intended for human consumption? Trying to paginate it doesn't make a whole lot of sense to me.Deneendenegation
I don't want the sitemap to be paginated, I want the sitemap to generate items for my paginated pages -- IF that is a good idea. In the case of the news, I'm wondering if it'd be more useful to create permalinks, even if they don't show anything you can't see on the frontpage and paginated versions of it, so at least the sitemap contains those. The other thing I'm not sure about is how to generate a site map for a one-off page, in this case the index, which, while paginated, is the main page and I think should be on the sitemap anyway. If that makes sense.Reverberatory
M
13

I've included urls for my paginated list views in the XML sitemap using the following code:

from django.conf import settings
from django.contrib.sitemaps import Sitemap
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse

class ArticleListSitemap(Sitemap):
    def items(self):
        objects = Article.objects.all()
        paginator = Paginator(objects, settings.ARTICLE_PAGINATE_BY)
        return paginator.page_range

    def location(self, page):
        return reverse('article_list', kwargs={'page': page})
Mclellan answered 11/10, 2011 at 7:3 Comment(1)
Oh hi! Yeah this is what I wanted. Thanks for actually understanding what I was asking for. I've decided I'm probably not going to do this, but thanks for the example in case I change my mind (always a possibility with me).Reverberatory

© 2022 - 2024 — McMap. All rights reserved.