• Hi,

    I bumped into this problem and I just can’t figure it out…

    I’ve customized the single.php file, so that now when it’s in category 3 it automatically loads “single-3.php” which works fine. BUT the problem is that the links above the post which show next and previous posts doesn’t distinguish the category, so that if you click through them you end up seeing the posts from other category and that’s is a problem because the single post page has a graphical header for category 3.

    Is there anyway that I can limit the next/previous links to show only from category 3?

    If you have any idea or have experience with this please let me know. Many thanks!

    AD

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you tried something like:

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

    https://codex.www.ads-software.com/Template_Tags/next_post_link#Text_As_Link.2C_Without_Post_Title.2C_Within_Same_Category

    Thread Starter Agent D

    (@agent-d)

    Hmm… I just tried it but still shows posts from other categories… I also would like to show the title of the post instead of “next post in category”. Any other suggestions? Thank you.

    AD

    Thread Starter Agent D

    (@agent-d)

    Ok, I figured out how to post display the title but still haven’t been able to figure out the category issue. The thing is that Category 3 is a child category(or sub category) of Category 1. DO you think that is the issue?

    AD

    I had the same problem. I renamed ‘single.php’ to ‘single-default.php’, then made a copy of it to ‘single-in-category.php’.

    In my theme, I only needed to change two lines in ‘single-in-category.php’.

    From:

    <div class="alignleft"><?php previous_post_link('&laquo; %link &laquo;') ?></div>
    <div class="alignright"><?php next_post_link('&raquo; %link &raquo;') ?></div>

    To:

    <div class="alignleft"><?php previous_post_link('&laquo; %link &laquo;','%title',TRUE) ?></div>
    <div class="alignright"><?php next_post_link('&raquo; %link &raquo;','%title',TRUE) ?></div>

    Then I wrote a new ‘single.php’ to call ‘single-in-category.php’ if it was one of the categories I wanted to restrict, otherwise, call ‘single-default.php’.

    I am a relative newbie to WP, so there might be an easier way, but this worked for me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Single post: Show posts “only” from the category with the next/previous links?’ is closed to new replies.