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

Discussion forum for MOD Writers regarding MOD Development.
User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK

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

Post 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
Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve

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

Post 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
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
User avatar
Lumpy Burgertushie
Registered User
Posts: 69228
Joined: Mon May 02, 2005 3:11 am

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

Post by Lumpy Burgertushie »

what would be the benefit of these tags in the head section?


robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
AmigoJack
Registered User
Posts: 6127
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK

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

Post 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.
ToonArmy
Former Team Member
Posts: 4608
Joined: Sat Mar 06, 2004 5:29 pm
Location: Worcestershire, UK
Name: Chris Smith

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

Post 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 -->
Chris SmithGitHub
Pony99CA
Registered User
Posts: 4783
Joined: Thu Sep 30, 2004 3:13 pm
Location: Hollister, CA
Name: Steve

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

Post 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
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.
User avatar
AmigoJack
Registered User
Posts: 6127
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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.)
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK

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

Post by alecrust »

That works great! Thank you :)
User avatar
AmigoJack
Registered User
Posts: 6127
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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 ): '' ),  
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK

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

Post 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?
User avatar
AmigoJack
Registered User
Posts: 6127
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post by AmigoJack »

The rel="prev" URL on a second page won't get assigned a start parameter anymore.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Oyabun1
Former Team Member
Posts: 23162
Joined: Sun May 17, 2009 1:05 pm
Location: Australia
Name: Bill

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

Post 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.
                      Support Request Template
3.0.x: Knowledge Base Styles Support MOD Requests
3.1.x: Knowledge BaseStyles SupportExtension Requests
User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK

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

Post 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?
User avatar
AmigoJack
Registered User
Posts: 6127
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28

Return to “[3.0.x] MOD Writers Discussion”