WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Next/Previous links within category [Twentyeleven] (12 posts)

  1. nicholsj
    Member
    Posted 2 years ago #

    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">&larr;</span> Previous', TRUE,'twentyeleven' ) ); ?></span>
    <span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">&rarr;</span>', TRUE, 'twentyeleven' ) ); ?></span>

    The links still ignore the category and just go by date.

    Any help much appreciated

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  3. nicholsj
    Member
    Posted 2 years ago #

    Thanks for your response. Sorry, I should have clarified that yes, I've already created a child theme.

    I'm only assuming that the

    'twentyeleven'
    bit in the code is referring to the theme.

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  5. nicholsj
    Member
    Posted 2 years ago #

    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.

  6. LucyRyder
    Member
    Posted 2 years ago #

    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">&larr;</span> Previous', TRUE); ?></span>
    
    <span class="nav-next"><?php next_post_link('%link', 'Next <span class="meta-nav">&rarr;</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!

  7. spherical
    Member
    Posted 2 years ago #

    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?

  8. binarybedouin
    Member
    Posted 2 years ago #

    Yo guys try this:

    <span class="nav-previous"><?php previous_post_link('%link','&larr; Previous ', TRUE, 'Next post in category', TRUE);?></span>
    
    <span class="nav-next"><?php next_post_link('%link', 'Next &rarr;', TRUE,'Next post in category', TRUE);?></span>
  9. nicholsj
    Member
    Posted 2 years ago #

    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..)

  10. kush_21
    Member
    Posted 1 year ago #

    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>

    'Incorrect:
    <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', TRUE,'twentyeleven' ) ); ?></span>'

  11. nicholsj
    Member
    Posted 1 year ago #

    Kush_21 - that works, thanks a lot!

  12. nicholsj
    Member
    Posted 1 year ago #

    Marking as resolved - seems moving the TRUE parameter outside the brackets works. Documentation needs updating though..

Topic Closed

This topic has been closed to new replies.

About this Topic