Page 1 of 2

Pagination with rel="next" and rel="prev"

Posted: Wed Sep 21, 2011 3:45 pm
by alecrust
Hi,

As some of you may know, Google recently announced that you can now start using rel="next" and rel="prev" to indicate what the next and previous pages of paginated content are. Very useful for phpBB boards!

The implementation is simple:

On the first page, http://www.example.com/article?story=abc&page=1, you’d include in the <head> section:

Code: Select all

<link rel="next" href="http://www.example.com/article?story=abc&page=2" />
On the second page, http://www.example.com/article?story=abc&page=2:

Code: Select all

<link rel="prev" href="http://www.example.com/article?story=abc&page=1" />
<link rel="next" href="http://www.example.com/article?story=abc&page=3" />
On the third page, http://www.example.com/article?story=abc&page=3:

Code: Select all

<link rel="prev" href="http://www.example.com/article?story=abc&page=2" />
<link rel="next" href="http://www.example.com/article?story=abc&page=4" />
And on the last page, http://www.example.com/article?story=abc&page=4:

Code: Select all

<link rel="prev" href="http://www.example.com/article?story=abc&page=3" />
Is there a simple way of achieving this in phpBB, or does a MOD need to be written for it?

Many thanks,
Alec

Re: Pagination with rel="next" and rel="prev"

Posted: Thu Sep 22, 2011 1:07 am
by Pony99CA
Look in overall_header.html (or do a View Source on your board). Do you sae any LINK tags with REL? Probably not, so it would require a MOD.

The MOD shouldn't be too difficult. Create two new template variables in overall_header.html to hold LINK tags ({PREV_PAGE} and {NEXT_PAGE}, for example). You'll need those set to null strings for every page in general (maybe see how the breadcrumbs are done), but on pages with pagination, if a previous and/or next page exists, take the URLs for those and create LINK tags using those URLs and assign them to the template variables.

Steve

Re: Pagination with rel="next" and rel="prev"

Posted: Thu Sep 22, 2011 3:56 am
by Lumpy Burgertushie
what would be the benefit of these tags in the head section?


robert

Re: Pagination with rel="next" and rel="prev"

Posted: Fri Sep 23, 2011 7:53 am
by AmigoJack
alecrust wrote:Google recently announced that you can now start using rel="next" and rel="prev"
It may surprise you, but that HTML element and the purpose of the rel attribute exist since HTML2 (and its SGML, which both was in 1995). In other words: welcome to the past, Google (or alecrust). :P

Re: Pagination with rel="next" and rel="prev"

Posted: Fri Sep 23, 2011 2:32 pm
by alecrust
Pony99CA wrote: Look in overall_header.html (or do a View Source on your board). Do you sae any LINK tags with REL? Probably not, so it would require a MOD.

The MOD shouldn't be too difficult. Create two new template variables in overall_header.html to hold LINK tags ({PREV_PAGE} and {NEXT_PAGE}, for example). You'll need those set to null strings for every page in general (maybe see how the breadcrumbs are done), but on pages with pagination, if a previous and/or next page exists, take the URLs for those and create LINK tags using those URLs and assign them to the template variables.
Thanks for this Steve, although it's a little too technical on the PHP side of things for me. Could you be more specific?
Lumpy Burgertushie wrote:what would be the benefit of these tags in the head section?
Read the first post in the topic or follow the provided link for more information.
AmigoJack wrote:It may surprise you, but that HTML element and the purpose of the rel attribute exist since HTML2 (and its SGML, which both was in 1995). In other words: welcome to the past, Google (or alecrust). :P
As true as this is, it's never really been utilised properly before. With Google's recent adoption of this, it could become quite a powerful SEO tool.

Re: Pagination with rel="next" and rel="prev"

Posted: Fri Sep 23, 2011 8:38 pm
by ToonArmy
You can try adding this to styles/prosilver/template/overall_header.html:

Code: Select all

<!-- IF PREVIOUS_PAGE --><link rel="prev" href="{PREVIOUS_PAGE}" /><!-- ENDIF -->
<!-- IF NEXT_PAGE --><link rel="next" href="{NEXT_PAGE}" /><!-- ENDIF -->

Re: Pagination with rel="next" and rel="prev"

Posted: Fri Sep 23, 2011 9:33 pm
by Pony99CA
ToonArmy wrote:You can try adding this to styles/prosilver/template/overall_header.html:

Code: Select all

<!-- IF PREVIOUS_PAGE --><link rel="prev" href="{PREVIOUS_PAGE}" /><!-- ENDIF -->
<!-- IF NEXT_PAGE --><link rel="next" href="{NEXT_PAGE}" /><!-- ENDIF -->
Those template variables already exist? That would make the problem much simpler. :D

Steve

Re: Pagination with rel="next" and rel="prev"

Posted: Sat Sep 24, 2011 8:40 am
by AmigoJack
Pony99CA wrote:
ToonArmy wrote:You can try adding this to styles/prosilver/template/overall_header.html:

Code: Select all

<!-- IF PREVIOUS_PAGE --><link rel="prev" href="{PREVIOUS_PAGE}" /><!-- ENDIF -->
<!-- IF NEXT_PAGE --><link rel="next" href="{NEXT_PAGE}" /><!-- ENDIF -->
Those template variables already exist?
Oh yes (I also didn't know). They're filled when pagination is used (speak: always if you have something which spans on more than one page, like 300 posts in one topic, or 300 members when viewing the memberlist etc.)

Re: Pagination with rel="next" and rel="prev"

Posted: Sat Sep 24, 2011 4:47 pm
by alecrust
That works great! Thank you :)

Re: Pagination with rel="next" and rel="prev"

Posted: Mon Sep 26, 2011 6:53 am
by AmigoJack
However, the function also produces ...&start=0 links and Google might see that as different site again than without that parameter. So you'd better open /includes/functions.php and find:

Code: Select all

        $tpl_prefix . 'PREVIOUS_PAGE'    => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page), 
Replace with:

Code: Select all

        //$tpl_prefix . 'PREVIOUS_PAGE'    => ($on_page == 1) ? '' : $base_url . "{$url_delim}start=" . (($on_page - 2) * $per_page),
        $tpl_prefix . 'PREVIOUS_PAGE'=> $on_page== 1? '': $base_url. ( ( $on_page- 2 )* $per_page> 0? "{$url_delim}start=". ( ( $on_page- 2 )* $per_page ): '' ),  

Re: Pagination with rel="next" and rel="prev"

Posted: Mon Sep 26, 2011 11:31 pm
by alecrust
Thanks for your code change. Upon applying that though it hasn't seemed to make any different to the contents of the rel="prev" or rel="next" links. What is it supposed to be doing?

Re: Pagination with rel="next" and rel="prev"

Posted: Tue Sep 27, 2011 5:34 am
by AmigoJack
The rel="prev" URL on a second page won't get assigned a start parameter anymore.

Re: Pagination with rel="next" and rel="prev"

Posted: Tue Sep 27, 2011 8:19 am
by Oyabun1
This may be of interest as well, it seems page numbers may be added to page titles in the next phpBB version, see this bug report, Optimized Page Titles, that includes a patch than can be used now.

Re: Pagination with rel="next" and rel="prev"

Posted: Wed Sep 28, 2011 7:28 pm
by alecrust
That code change seems to take away the &start=0 from URLs pointing to the first page in a topic, but no others. This is correct right?

Re: Pagination with rel="next" and rel="prev"

Posted: Wed Sep 28, 2011 7:31 pm
by AmigoJack
alecrust wrote:That code change seems to take away the &start=0 from URLs pointing to the first page
Yes, since start=0 is the same as no start at all.
alecrust wrote:in a topic, but no others
No, it affects every case where pagination is used - not only topics.