Forums

[resolved] Fixing it so previous and next links stay within same category (4 posts)

  1. 82tenten
    Member
    Posted 7 months ago #

    I found the code in my template (Bueno Theme) for the previous and next post links on my singlepost.php

    I want this to be changed to STAY WITHIN THE SAME CATEGORY when the user clicks next. That way it doesn't take them to the next post by date. This is because I have an anime site and each category is posts containing episodes of an anime. I want them to be able to click through to the next episode without ending up at some random other post I have made.

    <div class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> %title' ) ); ?></div>
    
    <div class="nav-next"><?php next_post_link( '%link', __('%title <span class="meta-nav">→</span>') ); ?></div>

    Does this request make sense?

    Also are there any other pages I might need to update this code as well? Maybe for archive functions?

    I am pretty new to wordpress. If anyone has experience building an anime site with WP and can help me with other areas, please email me at [contact details moderated]

    This task right here is my most urgent one though. Without this fix I am kinda screwed....

    -Chelsea (animepanda.net)

  2. alchymyth
    The Sweeper
    Posted 7 months ago #

    http://codex.wordpress.org/Function_Reference/next_post_link
    http://codex.wordpress.org/Function_Reference/previous_post_link

    example:

    <div class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> %title' ), true ); ?></div>
    
    <div class="nav-next"><?php next_post_link( '%link', __('%title <span class="meta-nav">→</span>'), true ); ?></div>
  3. 82tenten
    Member
    Posted 7 months ago #

    Thank you very much! I had found those reference links earlier but couldn't figure out how to work the 'true' into the code... when I tried I guess I had it in the wrong place and it broke the whole page...

    I will give this a try. Thanks again!

  4. 82tenten
    Member
    Posted 7 months ago #

    Worked like a charm. Thank you very much!

Reply

You must log in to post.

About this Topic