WordPress.org

Ready to get started?Download WordPress

Forums

Single post: Show posts "only" from the category with the next/previous links? (5 posts)

  1. Agent D
    Member
    Posted 4 years ago #

    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

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Have you tried something like:

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

    http://codex.wordpress.org/Template_Tags/next_post_link#Text_As_Link.2C_Without_Post_Title.2C_Within_Same_Category

  3. Agent D
    Member
    Posted 4 years ago #

    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

  4. Agent D
    Member
    Posted 4 years ago #

    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

  5. vtxyzzy
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic