• I want to create a special category, let’s call it “motorcycles” just for the sake of example.

    I want to create a page that will list all posts under the “motorcycles” category on the page. I can get this far.

    However, when the user selects a post from that list to read said post, I want the “previous” and “next” post links to go to the previous/next post in the “motorcycles” category only – I want to exclude all non-motorcycles posts in the previous and next links.

    Is this easy to do and I’m just missing something?

Viewing 7 replies - 31 through 37 (of 37 total)
  • Does the new release make it any easier to control previous and next posts based on the category of the current post?

    Yes, you have two extra arguments for previous_post_smart() and next_post_smart(): $in_same_cat and $excluded_categories.

    This is how the function prototype looks like:

    previous_post_smart(
    	$format = '« %link',
    	$title = '%title',
    	$fallback = true,
    	$in_same_cat = false,
    	$excluded_categories = ''
    );

    I think the code was provided in the above comments, but I can’t seem to get it to work the way I desire.

    This is my current code:
    <div style=”float:left;”><?php previous_post_smart(); ?></div>
    <div style=”float:right;”><?php next_post_smart(); ?></div>
    <div style=”clear:both;”></div>

    I have 3 custom individual single.php pages. One is a single-photo_of_the_Day.php. This post only applies to the category of “Photo of the Day” (ID-10). When someone clicks on one of my Photo of the Day posts from my homepage they are taken to single-photo_of_the_Day.php. How can I then ensure that the previous and next links only show posts in that category, even though they didn’t come to this page via a category selection?

    Thank you.

    https://www.twobackpackers.com

    You just have to set the $in_same_cat parameter to true:

    previous_post_smart('&laquo; %link', '%title', true, true);

    It doesn’t work on my blog too ??
    https://www.twitterevolutions.com/

    anyone can help?

    thanks!

    I think the problem is that I have posts in multiple categories.
    If Scribu can tell me how to use get_referrer_category() I would really appreciate it.

    There’s not much explanations on the download page.

    thanks!

    I think the problem is that I have posts in multiple categories.

    No, that’s not the problem.

    previous_posts_smart() and next_posts_smart() can handle posts in multiple categories.

    If Scribu can tell me how to use get_referrer_category() I would really appreciate it.

    https://www.ads-software.com/support/topic/366588?replies=6#post-1424738

    There’s not much explanations on the download page.

    I’ve updated the readme. Hopefully, it’s clearer now.

Viewing 7 replies - 31 through 37 (of 37 total)
  • The topic ‘Previous/Next Post in Category?’ is closed to new replies.