Here's a very simple patch...

I noticed that the default pager's links were missing rel attributes, which can be useful if you happened to have become addicted to some Site Navigator browser extension... With this Drupal 5.0 patch, the pager will make the browser aware of first, prev, next and last links, where that feature is available, of course...

Included with this post is a diff file for the includes/pager.inc script I generated from winMerge. I'm sorry I couldn't post a more standard compliant patch. As I'm still just getting acquainted with Drupal's internals, I haven't set up my installation under a full development environment.

I hope it helps more than it annoys...

Comments

cosmicdreams’s picture

Project: » Drupal core
Version: » 6.x-dev
Component: usability » base system

has this change been implemented in Drupal already? I'm going to triage this out to the drupal project so that it can be properly addressed.

stevenpatz’s picture

Status: Needs work » Needs review

Set to review for more eyes to look at.

geodaniel’s picture

StatusFileSize
new1.65 KB

Here's an updated patch against 6.0b2.

I'm not sure this has the right behaviour when there are only two pages though. Right now, on the first page, the link to the second page should be the same as 'next' but both are tagged with rel last, which is also true, but perhaps not expected behaviour?

pancho’s picture

Status: Needs review » Needs work

This is a small but good improvement. However we need to fix the problem geodaniel points us to in #3.

lilou’s picture

Version: 6.x-dev » 7.x-dev

+1

lilou’s picture

It would be nice to also add <link rel="prev"> and <link rel="next"> to the <head> like in book module.

See also : http://www.w3.org/TR/REC-html40/types.html#type-links and #35153: META LINK REL support. New feature? New Module?

cosmicdreams’s picture

The way the book module handles these kind of attributes is described here: http://api.drupal.org/api/function/template_preprocess_book_navigation/7

Perhaps we should approach this the same way. For Drupal 7 the API for theme_pager_next has changed. The new API supports the passing in of any kind of extra attribute though the parameters variable. http://api.drupal.org/api/function/theme_pager_next/7

I'll see if I can get a patch in for the administrative theme Seven as a starting point for further discussion.

cosmicdreams’s picture

Are there any cases where we don't want the extra attributes on these pager links?

cosmicdreams’s picture

StatusFileSize
new2.99 KB

I look into how nodes and polls call upon the pager and there doesn't seem to be an opprotunity to pass into pager additional attributes for the links that are generated. Which means I could attempt to implement a pre-process function to the themes templates OR attempt to modify pager.inc to include the extra attributes for links.

I'll try to do both patches and see which one gathers support.

cosmicdreams’s picture

StatusFileSize
new3.17 KB

sorry, looks like there were some commits before last patch.

cosmicdreams’s picture

StatusFileSize
new4.79 KB

Here's an example implementation of it is possible to put this code in the pre-process stage for a specific theme. Please, let me know if I'm on the right path here.

cosmicdreams’s picture

I don't understand why my patches are being ignored by the test bot.

lilou’s picture

Status: Needs work » Needs review
cosmicdreams’s picture

#11: pager-rel3.patch queued for re-testing.

dries’s picture

Any reason why we do this in Seven, and not in the base implementation? We should try to add this to every theme by tackling this at a higher level IMO.

cosmicdreams’s picture

No reason, I've just been focusing on Seven. I'll see if I can generalize this patch.

cosmicdreams’s picture

Dries, are you suggesting that I modify the /misc/theme.inc or the /sites/all/themes/engines/phptemplate.engine when you ask me to look at moving this patch to a higher level?

To me both places seem to be poor places for this patch. theme.inc already provides the functions that can generate the pager links as we need them to here. And phptemplate.engine seems to be a bad place in general.

dries’s picture

I was thinking it should be part of theme.inc -- any reason it should not be?

dries’s picture

Status: Needs review » Needs work
mcncyo’s picture

Status: Needs work » Needs review

#3: pager_rel.patch queued for re-testing.

droplet’s picture

Version: 7.x-dev » 8.x-dev
Priority: Minor » Normal
Status: Needs review » Needs work
zhuber’s picture

Version: 8.x-dev » 6.22
Category: task » feature
Status: Needs work » Needs review
StatusFileSize
new2.99 KB

I have implemented this in drupal 6 by modifying pager.inc. I'm putting it up here for anyone who may find it useful.

Status: Needs review » Needs work

The last submitted patch, pager_ga-115753.patch, failed testing.

stevenpatz’s picture

Version: 6.22 » 8.x-dev
Category: feature » task
nate.dame’s picture

Saw this in Google's Webmaster central blog, was curious if it's been implemented in Drupal. This string is the closest I've found...

http://googlewebmastercentral.blogspot.com/2012/03/video-about-paginatio...

drclaw’s picture

Status: Needs work » Needs review
StatusFileSize
new2.23 KB

Here's a D8 patch that should do the trick...

drclaw’s picture

StatusFileSize
new2.21 KB

It passed!

Here's a D7 patch for anyone who is interested

oriol_e9g’s picture

Status: Needs review » Reviewed & tested by the community

Yeah! This is the way!

dries’s picture

Version: 8.x-dev » 7.x-dev

Committed to 8.x. Updating the version so we can consider it for inclusion in 7.x. Thanks!

msellers’s picture

If I understand this patch correctly, it modifies the pager links to include the rel="prev" and rel="next" attributes.

From what I understand by reading the Google docs, the implementation should place in the section of the document, a

for the first page, both
and
on page 2, etc

I don't think this patch does what google wants. What am I missing?

msellers’s picture

Wow. I placed the tag in #30 and it was filtered out! Anyway, second paragraph should read:
... should place in the <head> section of the document

drclaw’s picture

Huh. How 'bout that. @msellers is correct it seems. According to google (http://googlewebmastercentral.blogspot.ca/2011/09/pagination-with-relnex...):

rel=”next” and rel=”prev” only need to be declared within the section, not within the document .

It seems like putting them in the <a> tags is a misconception... or something... And here I was thinking how easy it was to fix...

So what do we do here? All the logic about which page we're on and which page is next (etc.) is done in the theme function... but we probably shouldn't be adding drupal_add_html_head_link() into the theme function... Maybe in a preprocessor? We can preprocess theme functions now in D7 and D8 right?

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs review

Sounds like maybe this needs additional discussion/work for Drupal 8 still, then?

drclaw’s picture

StatusFileSize
new5.37 KB

I'm not sure if this is necessarily the correct approach but here's a first attempt. Here's a quick description:

1) Added a preprocessor for theme_pager() that adds the necessary links to the head tag
2) Created a new helper function that builds the pager link query (pulled the code out of theme_pager_link and made it a reusable function)

I'll just post the D8 Patch for now, but can backport it if accepted.

greatfield’s picture

For the time being until this is fixed in the core, i created something working for D6, based on this blog: http://pivica.me/blog/how-create-drupal-pagination-use-rel-next-and-rel-... (with some small changes). Just add the function to template.php. I hope this is of use to someone.

<?
function YOURTHEME_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) {
  $page = isset($_GET['page']) ? $_GET['page'] : '';
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
    $parameters['page'] = $new_page;
  }

  $query = array();
  if (count($parameters)) {
    $query[] = drupal_query_string_encode($parameters, array());
  }
  $querystring = pager_get_querystring();
  if ($querystring != '') {
    $query[] = $querystring;
  }

  // Set each pager link title
  if (!isset($attributes['title'])) {
    static $titles = NULL;
    if (!isset($titles)) {
      $titles = array(
        t('« first') => t('Go to first page'),
        t('‹ previous') => t('Go to previous page'),
        t('next ›') => t('Go to next page'),
        t('last »') => t('Go to last page'),
      );
    }
    if (isset($titles[$text])) {
      $attributes['title'] = $titles[$text];
    }
    else if (is_numeric($text)) {
      $attributes['title'] = t('Go to page @number', array('@number' => $text));
    }
  }

  $query = count($query) ? implode('&', $query) : NULL;

  static $rel_prev = FALSE, $rel_next = FALSE;
  if (!$rel_prev && $text == t('‹ previous')) {
    $rel_prev = TRUE;
    drupal_set_html_head('<link rel="prev" href="' . url($_GET['q'], array('query' => $query)) . '" />');
  }
  if (!$rel_next && $text == t('next ›')) {
    $rel_next = TRUE;
    drupal_set_html_head('<link rel="next" href="' . url($_GET['q'], array('query' => $query)) . '" />');
  }
  
  return l($text, $_GET['q'], array('attributes' => $attributes, 'query' => $query));
}
?>
mgifford’s picture

#34: pager_rel_attr-115753-34.patch queued for re-testing.

mgifford’s picture

mgifford’s picture

Issue tags: -SEO, -Accessibility

#34: pager_rel_attr-115753-34.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +SEO, +Accessibility

The last submitted patch, pager_rel_attr-115753-34.patch, failed testing.

netentropy’s picture

herderwu’s picture

D7 solution:
add two section code in theme_pager function(include/pager.inc), we could hook in template.php
1.rel="prev"

    if ($li_previous) {
      $items[] = array(
        'class' => array('prev'),//pager-previous=>prev
        'data' => $li_previous,
      );
      
      //Pages: rel="next" & rel="prev" on paginated pages
      preg_match("#<a.+?href=['\"](.+)['\"]>#i", $li_previous, $prev_match);
      $prev_link = invmodule_url_rewrite($prev_match[1]);
      drupal_add_html_head_link(array('rel' => 'prev', 'href' => $prev_link));
    }

2.rel="next"

    if ($li_next) {
      $items[] = array(
        'class' => array('next'),//pager-next=>next
        'data' => $li_next,
      );
      
      //Pages: rel="next" & rel="prev" on paginated pages
      preg_match("#<a.+?href=['\"](.+)['\"]>#i", $li_next, $next_match);
      $next_link = invmodule_url_rewrite($next_match[1]);
      drupal_add_html_head_link(array('rel' => 'next', 'href' => $next_link));
    }
mgifford’s picture

StatusFileSize
new1.27 KB

invmodule_url_rewrite() isn't defined which is a critical error. This is what was in the D7 example too.

Tere's a D8 patch with your code to help move this ahead.

mgifford’s picture

Status: Needs work » Needs review

forgot the bot.

Status: Needs review » Needs work
Issue tags: -SEO, -Accessibility

The last submitted patch, rel-115753-42.patch, failed testing.

mgifford’s picture

Status: Needs work » Needs review

#42: rel-115753-42.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +SEO, +Accessibility

The last submitted patch, rel-115753-42.patch, failed testing.

mgifford’s picture

Where did function theme_pager go?

stefan006’s picture

Hi greatfield! Your code works great. It gives me a dynamic link tags with atributes rel=prev and rel=next. Regards!!!

stefan006’s picture

Hi mgifford! function theme_pager_link is in folder includes->pager.inc

mgifford’s picture

I still can't find it with grep -ir theme_pager core/includes/*

Can't see how it is still there.

The patch was applied the theme_pager() in @@ -245,7 +245,12 @@ function theme_pager($variables) {

That must have been renamed.

aleksijohansson’s picture

invmodule_url_rewrite() gives not defined error. You can replace this line to get it working:

$next_link = invmodule_url_rewrite($next_match[1]);

with this line:

$next_link = $GLOBALS['base_url'] . $next_match[1];

mgifford’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.32 KB

Status: Needs review » Needs work

The last submitted patch, 52: rel-115753-52.patch, failed testing.

jwilson3’s picture

My issue with this patch is conceptual:

What happens if there are two sets of pagers on a page? Which one is determined to be the "main" pager, whose next/prev links make it up into the head section in the dom?

droplet’s picture

@jwilson3,

Shouldn't it only one Pager per page? In template_preprocess_pager function, it used global vars to indicated current pager status.

global $pager_page_array, $pager_total;
jwilson3’s picture

Search the codebase for the text 'multiple pagers'. The functionality is there, particularly for Comments, but I'm not sure how much test coverage there is for this feature.

mgifford’s picture

This is an old issue. But to get to @jwilson3 point, I don't know that it will matter.

There is nothing in the specs I could find which indicate that there is anything else that is needed for multiple pagers:
http://www.w3.org/TR/html5/links.html#link-type-next

I do think that machines (including assistive technology) will put the previous/next in context of the series of links that they are browsing. They will be nested semantically with a group of other links.

I don't know how to prove this though, but it is next within a context of a series of links, not just a bunch of random links.

The whole patch needs to be rewritten but at least the functions still exist in core/includes/pager.inc core/includes/theme.inc

tanmoy1981’s picture

Please check my solution here.

mgifford’s picture

So essentially:

    // Add rel attribute.
    if ($text == t('‹ previous')) {
      $attributes['rel'] = 'prev';
    }
    elseif ($text == t('next ›')) {
      $attributes['rel'] = 'next';
    }

Not sure how that deals with the issue of multiple pagers though.

tanmoy1981’s picture

@mgifford - This solution will work properly with multiple pagers as well.
You need some minor modifications if you change the prev or next texts across different pagers.

mgifford’s picture

@tanmoy1981 Can you roll up a patch for D8? If it's fixed in D8 for Views there's a better chance it will be backported. I still don't understand why that was marked Closed (Won't fix).

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed bd40855 on 8.3.x
    - Patch #115753 by cosmicdreams, drclaw, geodaniel, zhuber, urlisse:...

  • Dries committed bd40855 on 8.3.x
    - Patch #115753 by cosmicdreams, drclaw, geodaniel, zhuber, urlisse:...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed bd40855 on 8.4.x
    - Patch #115753 by cosmicdreams, drclaw, geodaniel, zhuber, urlisse:...

  • Dries committed bd40855 on 8.4.x
    - Patch #115753 by cosmicdreams, drclaw, geodaniel, zhuber, urlisse:...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joe huggans’s picture

.

mgifford’s picture

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

  • Dries committed bd40855 on 9.1.x
    - Patch #115753 by cosmicdreams, drclaw, geodaniel, zhuber, urlisse:...

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

Status: Needs work » Postponed (maintainer needs more info)

I'm following up on issues that have been committed and re-opened.

This issue was committed to Drupal 8.x in 2012 and re-opened in #33 due to questions about the implementation. The last discussions were 7 years ago.

Is there anything still to do here? Is, update the Issue Summary and add a comment.

Thanks

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Postponed (maintainer needs more info) » Fixed

There hasn't been any further information provided so I am marking this as fixed, because it was committed to Drupal 8.

Cheers.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.