Problem/Motivation

I want to set a canonical tag on any page of my drupal installation. Using the default setting for node type pages is no problem. For taxononmies the default term could be changed, too. But here the problem arises. My front page as well as some of my taxonomy term pages are paginated into several parts. So, the URL of the first term page is e.g. http://trekkingschuhe-test.de/tags/trekkingschuh, the URL of the second one then is http://trekkingschuhe-test.de/tags/trekkingschuh?page=1 . In fact, the first URL without the GET parameter is internally handled identically to ?page=0

My idea was to set

[current-page-url]?page=[current-page-number]

as default canonical meta tag in admin/content/taxonomy/edit/vocabulary/1

This does not work, as [current-page-number] does start with 1 not 0. So the resulting canonical URL is just one step to high :-( Setting any page of the paginated list to the same taxonomy URL in the canonical tag would ruin the given backlink structure of sites.

I initially posted this issue to the nodewords project, cf. here: http://drupal.org/node/1300376

Proposed resolution

I found out, the issue is not a problem with nodewords but with the token module. I´d applied a patch against token.module which works for me.

123a124,128
>       if ((int)$page > 0) {
>           $values['current-pager-ext'] = "?page=".((int) $page);
>       } else {
>           $values['current-pager-ext'] = "";
>       }
159a165
>     $tokens['global']['current-pager-ext']     = t('The current GET extension for pagination');

This simple patch gives me a new global token, which is counted correctly for any page > 0 and empty for the first page. After applying that patch, you can enter

[current-page-url][current-pager-ext]

als canonical URL with nodewords & nodewords tokens enabled.

Remaining tasks

I´d like to ask the community as well as the maintainers of the token module to review this small patch and merge it up into the next version.

Comments

pdreuw’s picture

.. nonsense, deleted, sorry

Dave Reid’s picture

Status: Needs review » Closed (won't fix)

Canonical tags should just reference the first page, I would recommend you should be linking to just [current-page-url] without any query string. That aside, I don't feel very good about adding this. I'm not sure it would be useful for most people using Token.

pdreuw’s picture

Status: Closed (won't fix) » Needs review

> Canonical tags should just reference the first page

Where do you find this in the Google docs?

If I do this, I will loose any downlinks to older articles. This would have a severe impact on the internal link structure.

Furthermore I´d think, a service module like token should give some desired service but not decide, how this service is used.
I just do see a discrepancy between the token value of [current-page-number] and the really used parameter for paging. My use for a canonical tag is just one possible use for the correct pager code.

Dave Reid’s picture

Marked #1498800: wrong page number, always +1 as a duplicate of this issue.

bluegeek9’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)