Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#10867 closed enhancement (fixed)

next_post_link() and previous_post_link() should be allowed in the loop, even if is_single()

Reported by: jobjorn's profile jobjorn Owned by:
Milestone: 3.0 Priority: low
Severity: normal Version:
Component: Themes Keywords: has-patch 2nd-opinion
Focuses: Cc:


I'm building a custom theme where the front page ( is essentially an exact duplicate of a single post ( Imagine my confusion when I copied the contents of single.php over to index.php and finding that the navigation links had disappeared.

I promptly tracked down the culprit, and it turned out to be a requirement in get_adjacent_post: if !is_single, it returns null.

I see no reason as to why these links should not be allowed everywhere in the loop. The codex page even states it is allowed in the loop, not telling of the extra limitations. Unless there is some reason of which I am not aware, I suggest that the attached patch be applied.

Attachments (2)

patch for not able to use next_post_link and previous_post_link on index page.diff (360 bytes) - added by jobjorn 15 years ago.
10867.2.diff (1.4 KB) - added by ryan 14 years ago.

Download all attachments as: .zip

Change History (12)

#1 @jobjorn
15 years ago

  • Keywords has-patch added

#2 @Denis-de-Bernardy
14 years ago

  • Keywords 2nd-opinion added; themes the-loop removed
  • Milestone changed from Unassigned to 3.0

it could be argued they could be used for attachments, too (i.e. next gallery image)

#3 @nacin
14 years ago

I agree we should remove the !is_single() and is_attachment() checks, but could this potentially suddenly have links show up in themes?

#4 @scribu
14 years ago

Agree on removing is_attachment() too.

Yeah, links might pop up in 0.01% of themes, but I doubt there would be a backlash over the issue.

#5 @nacin
14 years ago

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

(In [13475]) Allow get_(previous|adjacent|next)_post() to be used on attachment and !single templates. props jobjorn, fixes #10867

#6 @mdawaffe
14 years ago

  • Resolution fixed deleted
  • Severity changed from trivial to normal
  • Status changed from closed to reopened

There are several themes (Journalist, Garland, presumably many others) that use previous_post_link()/next_post_link() on index.php without wrapping them in is_singular() conditionals.

Prior to 3.0, the links would not show unless the current page was is_singular(). Now they show up on all pages including the front page.

I like the 3.0 versions better (more flexible), but they break some themes.


Could leave as is.
Could revert.
Could add a new argument (or convert it them to wp_parse_args() based functions).
Could ...?

#7 @ryan
14 years ago

This also causes two pointless queries for every page because adjacent_posts_rel_link() is hooked to wp_head. Attached patch solves that given the current code.

14 years ago

#8 @ryan
14 years ago

(In [14019]) Trigger adjacent_posts_rel_link() from wp_head only for single post pages to avoid unnecessary queries. see #10867

#9 @mdawaffe
14 years ago

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

MarkJaquith, nacin, ryan and I chatted about this OOB. We looked through themes in and decided that while this change breaks back compat, it doesn't affect too many themes. Most are either already wrapping in is_singular() conditionals or using them in single.php only.

We decided the back compat problems are worth the additional flexibility.

I guess we should sent something out to theme devs about this?

#10 @mdawaffe
14 years ago

Obviously, feel free to object/reopen/discuss :)

Note: See TracTickets for help on using tickets.