Next Post and Previous Post navigate only in same category

Discussion in 'WordPress' started by Investdeluxe, Sep 26, 2011.

  1. #1
    I have already read up on it and tried numerous times and I just can't get it to work. I have already read: http://codex.wordpress.org/Function_Reference/previous_post_link but everytime i try i just get errors or it doesn't work at all. Here is what my code looks like:

    <div class="nav-previous">
    <?php next_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'thirdstyle' ) . '</span> %title' ); ?></div>

    <div class="nav-next">
    <?php previous_post_link( '%link', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'thirdstyle' ) . '</span>' ); ?></div>

    I just want it so that the Previous post and Next Post links only navigate to posts with-in the same category of the current post.

    I hope someone can help me out!
     
    Investdeluxe, Sep 26, 2011 IP
  2. Thomas U

    Thomas U Active Member

    Messages:
    175
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    <?php next_post_link('format', 'link', 'in_same_cat', 'excluded_categories'); ?>

    You would write "TRUE" in place of the "in_same_cat" text.
     
    Thomas U, Sep 27, 2011 IP