I’ve seen this asked a few times, but couldn’t find an open discussion.
I’d like the Previous and Next links to stay within the same category as the current post. The codex says its possible with a ‘True’ parameter but I can’t get it to work.
The codex (http://codex.wordpress.org/Template_Tags/previous_post_link) doesn’t mention why the default theme code includes ‘twentyeleven’ as a parameter.
My code in single.php is:
<span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', TRUE,'twentyeleven' ) ); ?></span> <span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', TRUE, 'twentyeleven' ) ); ?></span>
The links still ignore the category and just go by date.
Any help much appreciated
Do not edit the Twenty Eleven theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. Create a child theme for your changes. Once your child theme is active, we should be able to help with the customisation.
Thanks for your response. Sorry, I should have clarified that yes, I’ve already created a child theme.
I’m only assuming that the
bit in the code is referring to the theme.
You need to look at the twentyeleven_content_nav() function in the parent theme’s functions.php file. That’s the function that you will need to customise in your child’s functions.php file.
Thanks. I’m a WP novice and struggling to work out what’s required, so sorry if I’m missing something obvious.
Are you saying that the “in_same_cat” parameter of previous_post_link isn’t relevant in this case? I can change the link text and it shows up, so its obviously doing something (and not being overriden by the function).
The twenty_eleven_content_nav() function is here http://pastebin.com/0wHuuTbC. As far as I can tell there’s no ability to keep navigation within category.
Hi nicholsj –
I too was trying to do the same as you, using a child theme for twentyeleven.
Also thinking that the page on Codex about Function reference / next link does not explain what the extra bits of code about twentyeleven are for, as per your code in the first post here, decided to try and take that out and go to the basics so i have used:
<span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">←</span> Previous', TRUE); ?></span> <span class="nav-next"><?php next_post_link('%link', 'Next <span class="meta-nav">→</span>', TRUE); ?></span>
And it seems to be working fone, only next and previous-ing to posts in the same category.
Let me know what you think!
I’ve seen this so many times…. Can someone please read the OP’s question and just simply answer it; instead of forking them off to some irrelevant path?
I’ve been searching for the same answer and, what with Google assuming that ‘twentyeleven’ must mean ” twenty eleven ” and returning all manner of magnitudes of irrelevant hits, the search is essentially useless in finding stuff about internal code constructs.
So, in I hope no uncertain terms:
1. What —exactly— is the ‘twentyeleven’ parameter in the theme code?
2. Can it be eliminated or is there a benefit to modifying it to match one’s child theme?
3. Is it necessary in a theme that is not a child of any theme?
4. In other words, what is that parameter for?
Yo guys try this:
<span class="nav-previous"><?php previous_post_link('%link','← Previous ', TRUE, 'Next post in category', TRUE);?></span> <span class="nav-next"><?php next_post_link('%link', 'Next →', TRUE,'Next post in category', TRUE);?></span>
Thanks for all the responses – sorry I haven’t replied earlier, but other stuff came up and I haven’t had a chance to try out the suggestions. Hopefully I’ll have time over the next few days. I’ll let you know how I get on.
Thanks again – much appreciated (and glad to hear I’m not the only one who’s found this problem..)
Hey all, I was having the same problem…
but figured it out after some time.
Place the TRUE parameter after the braces and not inside the braces like this:
Correct: <?php previous_post_link( '%link', __( 'Prev<span class="meta-nav"> </span> Previous', 'twentyeleven' ),TRUE ); ?></span>
<span class=”nav-previous”><?php previous_post_link( ‘%link’, __( ‘<span class=”meta-nav”>←</span> Previous’, TRUE,’twentyeleven’ ) ); ?></span>’
- The topic ‘Next/Previous links within category [Twentyeleven]’ is closed to new replies.