Make WordPress Core

Opened 17 years ago

Closed 15 years ago

#4209 closed enhancement (fixed)

Add rel="prev" to previous_post_link() and rel="next" to next_post_link()

Reported by: fekketcantenel's profile FekketCantenel Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version:
Component: Template Keywords: has-patch
Focuses: Cc:

Description

Hi,

I'm wondering if you could code link-template.php to include a rel="next" in the next_post_link()-generated link, and do the same with its previous counterpart.

This could even possibly be an option in the function's arguments. See also, this page.

My main use for this would be Opera's 'Flip Forward' and 'Flip Back' mouse gestures, which can use rel="" to detect where to go.

Attachments (5)

4209.diff (875 bytes) - added by Nazgul 17 years ago.
4209-nextgen.diff (3.8 KB) - added by rob1n 17 years ago.
4209.1.diff (637 bytes) - added by vladimir_kolesnikov 15 years ago.
Patch #1 (plugins have to check if rel is already there)
4209.2.diff (887 bytes) - added by vladimir_kolesnikov 15 years ago.
Patch 2 (we check if rel is already there)
link-template.php.diff (601 bytes) - added by vladimir_kolesnikov 15 years ago.
Updated version of 4209.1

Download all attachments as: .zip

Change History (38)

#1 @andy
17 years ago

I dig it.

#2 @rob1n
17 years ago

  • Milestone changed from 2.4 to 2.3

Yeah, I like it too. +1

#3 @rob1n
17 years ago

  • Owner changed from anonymous to rob1n

@Nazgul
17 years ago

#4 @Nazgul
17 years ago

  • Keywords has-patch added

#5 @FekketCantenel
17 years ago

Um, actually, I am stupid. This is an attribute for <LINK>, not <A>. I think.

Either way, I applied the mod but it isn't working with my flip gestures. I'm wondering if there might have to be a separate '<link rel="next" href="whatever">' added after the <A> tag.

#6 @FekketCantenel
17 years ago

Sure enough, this code works in Opera 9.20.8767:

	$string = '<link rel="prev" href="'.get_permalink($post->ID).'" /><a href="'.get_permalink($post->ID).'">'; 
	$string = '<link rel="next" href="'.get_permalink($post->ID).'" /><a href="'.get_permalink($post->ID).'">'; 

#7 @Nazgul
17 years ago

According to *1 the rel="next" is valid for an <a> tag.

Adding a <link> tag after/before the <a> tag may work, but isn't allowed, because <link> tags are only allowed in the <head> section *2.

*1 http://www.w3.org/TR/html4/struct/links.html#adef-rel
*2 http://www.w3.org/TR/html4/struct/links.html#edef-LINK

#8 @FekketCantenel
17 years ago

I think it must be a support issue in Opera itself. I'll keep my <link> usage for my personal use (since I'm the only one who sees my WordPress), and I hope other people will benefit from this patch. Thanks for all the info.

#9 @rob1n
17 years ago

We could put the <link /> tags for next/prev into the <head> automatically on is_single().

#10 @rob1n
17 years ago

  • Status changed from new to assigned

#11 @FekketCantenel
17 years ago

Interesting idea. Would that have to be added in the template itself?

#12 @rob1n
17 years ago

We can just add it as an action to wp_head. I'll work on a patch that incorporates Nazgul's as well as the <link /> ones.

#13 @rob1n
17 years ago

  • Keywords has-patch removed

#14 @rob1n
17 years ago

  • Keywords has-patch added

#15 @rob1n
17 years ago

  • Keywords commit added

Patch fully functional.

#16 @rob1n
17 years ago

I tested it in Opera, works fine. At first I needed to tweak something, but after that it was smooth sailing.

#17 @rob1n
17 years ago

  • Keywords commit removed

Never mind. Found an issue.

@rob1n
17 years ago

#18 @rob1n
17 years ago

  • Keywords commit added

Fully functional. Tested in Opera. Works.

#19 @rob1n
17 years ago

  • Keywords commit removed
  • Status changed from assigned to new

#20 @rob1n
17 years ago

  • Owner rob1n deleted

#21 @ryan
17 years ago

  • Milestone changed from 2.3 to 2.4

#22 @jatyap
16 years ago

I believe you can place a "rel" attribute inside the anchor (<a>) tag...

Check this: http://webdesign.about.com/od/htmltags/p/blatrel.htm

So the patch should work.

#23 @ffemtcj
16 years ago

  • Milestone changed from 2.5 to 2.6

#24 @mrmist
15 years ago

  • Keywords needs-patch added; has-patch removed

If this is still desired I'd expect the patch would need a fresh look.

#25 follow-up: @mtekk
15 years ago

The filters "next_posts_link_attributes" and "previous_posts_link_attributes" make implementing this quite difficult to do with out breaking any plugins that may add rel attributes using them.

#26 in reply to: ↑ 25 @vladimir_kolesnikov
15 years ago

  • Cc vladimir@… added

Replying to mtekk:

The filters "next_posts_link_attributes" and "previous_posts_link_attributes" make implementing this quite difficult to do with out breaking any plugins that may add rel attributes using them.

IMHO, plugins should also check if the rel attributte has already been added in order not to add it again :-)

@vladimir_kolesnikov
15 years ago

Patch #1 (plugins have to check if rel is already there)

@vladimir_kolesnikov
15 years ago

Patch 2 (we check if rel is already there)

#27 follow-up: @vladimir_kolesnikov
15 years ago

  • Component changed from Administration to Template
  • Keywords has-patch added; needs-patch removed

Attached two patches.

The first one adds rel="prev/next" before xxx_posts_link_attributes is fired, thus the plugins have to check if rel is already there (IMHO they should do that anyway).

The second one lets xxx_posts_link_attributes run, then checks if rel= is already there; if not, it is added.

Personally I like the first one more, as it is simplier and plugins in theory can add their own <a> tags in xxx_posts_link_attributes, in which case rel will be added to too many places.

#28 in reply to: ↑ 27 @mtekk
15 years ago

Replying to vladimir_kolesnikov:

Attached two patches.

The first one adds rel="prev/next" before xxx_posts_link_attributes is fired, thus the plugins have to check if rel is already there (IMHO they should do that anyway).

The second one lets xxx_posts_link_attributes run, then checks if rel= is already there; if not, it is added.

Personally I like the first one more, as it is simplier and plugins in theory can add their own <a> tags in xxx_posts_link_attributes, in which case rel will be added to too many places.

Looks like the functions dealing with this have changed, and that "next_posts_link_attributes" and "previous_posts_link_attributes" are now gone.

+1 on the first patch.

When using "next_post_link"/"previous_post_link" plugin authors should be able to see what is in the rel="" attribute. The first patch should be all that is needed for it to work since no one should be adding in rel="" before the new filters are run.

In the codex we should show how to intelligently add rel="" attributes, or others using the new filters.

#29 @Denis-de-Bernardy
15 years ago

I'm getting a malformed patch error with 4209.2.diff. 4209.1.diff applies clean and seems to do the right thing. is it rel=prev or rel=previous that we want?

#30 follow-up: @sivel
15 years ago

See #10180 and #8703.

WordPress 2.8 added home, index, next, prev.

#31 in reply to: ↑ 30 @vladimir_kolesnikov
15 years ago

Replying to sivel:

WordPress 2.8 added home, index, next, prev.

Maybe, but not to adjacent_post_link().

@vladimir_kolesnikov
15 years ago

Updated version of 4209.1

#32 @vladimir_kolesnikov
15 years ago

Updated the patch.

#33 @automattor
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11866]) Add rel attribute to next/previous post links. Fixes #4209 props vladimir_kolesnikov

Note: See TracTickets for help on using tickets.