1

The Codex disagrees with itself, so I'm stumped.

On single.php I am trying to use next_post_link() to display a link to the next post, with custom link text, within the same category as the current post.

The Codex article on next_post_link() says the parameters are $format, $link, $in_same_term, $excluded_terms, and $taxonomy. Its specific example for my scenario is

<?php next_post_link( '%link', 'Next post in category', TRUE ); ?>

But when I use that exact code, no link is output at all. The rest of the Post fully renders, it's just missing the next post link HTML completely.

If I take out just the "TRUE" it outputs a link almost as desired:

<?php next_post_link( '%link', 'Next post in category' ); ?>

But it links to the next Post in any category, and I need to restrict it to the current category.

The Codex article on Next and Previous Links contradicts the article specifically on next_post_link(). It says the parameters are $format, $text, and $title. That would mean that you can't restrict the link to posts within the current category. Since the Code Reference on next_post_link() matches the Codex on next_post_link() that seems likely to be the most accurate.

2 Answers 2

1

OK, so there's a problem with Codes in this part, I guess.

The Codex article on Next and Previous Links contradicts the article specifically on next_post_link()

In that article you can clearly see, that it looked a little bit different. In the part describing next_post_link there is a note:

Deprecated: previous_post() and next_post(). Use: --> previous_post_link() and next_post_link() instead.

So most probably it is describing some old params...

On the other hand, from PHP point of view...

The official PHP manual says:

To specify a boolean literal, use the keywords TRUE or FALSE. Both are case-insensitive.

So true === TRUE and false === FALSE.

On the PSR-2 standard requires true, false and null to be in lower case.

0

Ok, this seems silly, but for some reason lowercasing the "true" solved the problem.

<?php next_post_link( '%link', 'Next post in category', true ); ?>

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.