Detecting whether the current page is /blog/page/N/

Trying to port my fancypants breadcrumbs over to Hugo. I’ve managed to filter out spurious parent links elsewhere, but now that I’m adding pagination to the blog portion of my site, I’m stuck. I can understand if I’m asking the wrong question to solve my problem, but nobody seemed to know where these spurious additions come from.

Anyway, if I can detect that the current page is a generated pagination page, I should be OK, but for some reasons .URL is /blog/ on /blog/page/2/. How can I distinguish /blog/ from /blog/page/2/ if .URL, .RelPermalink, and .Permalink are the same for both?

I don’t have a specific answer to your question, but there are some posts on breadcrumbs here in the forum, and there’s a blog post here with an approach: https://gohugohq.com/partials/breadcrumb-partial-with-structured-data-in-hugo/

I don’t use pagination with Hugo @adiabatic, but I’m wondering what you get in your template when you use the .Kind page variable for each of the pagination pages. This might (untested) help you distinguish when you’re on a pagination page vs a section page. I will try to test later as well…

Nope. It’s “section” on both /blog/ and /blog/page/2/.

Thanks, though.

I may yet go back to a URL slice-and-dice; thanks for this.

There currently isn’t any good way of doing it.

There is a catch 22 situation going on here:

  1. Pagination pages aren’t created until you create/reference a Paginator in a template.
  2. You can do a check for .Paginator.PageNumber > 1 or something, but then you will create the paginator if not already created, which may be too early or not at all what you want …

We could (and maybe should) add some kind of indicator to the page itself, but that will demand some work … And a GitHub issue.

Issue #3287 submitted.

Thanks!

Hello,

any changes on this issue? I’m creating paginator later/deeper in template, but need to have info about it in header.