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
Contact:

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

Post by alecrust » Wed Sep 21, 2011 3:45 pm

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
Contact:

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

Post by Pony99CA » Thu Sep 22, 2011 1:07 am

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: 66865
Joined: Mon May 02, 2005 3:11 am
Contact:

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

Post by Lumpy Burgertushie » Thu Sep 22, 2011 3:56 am

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


robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

If a tree falls in the forest and nobody is there, does it make a sound?

User avatar
AmigoJack
Registered User
Posts: 5643
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Fri Sep 23, 2011 7:53 am

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 worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK
Contact:

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

Post by alecrust » Fri Sep 23, 2011 2:32 pm

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
Contact:

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

Post by ToonArmy » Fri Sep 23, 2011 8:38 pm

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
Contact:

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

Post by Pony99CA » Fri Sep 23, 2011 9:33 pm

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: 5643
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Sat Sep 24, 2011 8:40 am

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 worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK
Contact:

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

Post by alecrust » Sat Sep 24, 2011 4:47 pm

That works great! Thank you :)

User avatar
AmigoJack
Registered User
Posts: 5643
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Mon Sep 26, 2011 6:53 am

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 worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK
Contact:

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

Post by alecrust » Mon Sep 26, 2011 11:31 pm

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: 5643
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Tue Sep 27, 2011 5:34 am

The rel="prev" URL on a second page won't get assigned a start parameter anymore.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

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 » Tue Sep 27, 2011 8:19 am

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
Contact:

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

Post by alecrust » Wed Sep 28, 2011 7:28 pm

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: 5643
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Wed Sep 28, 2011 7:31 pm

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 worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

Locked

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