• Resolved sirawesome

    (@sirawesome)


    Hi,

    I need to be able to alter the behavior of the previous and next post widget to only show posts in the same category in the Twenty Twenty-Three theme. I created my own child theme to be able to add my customisations.

    I have found plenty of code explaning how to do this with non FSE themes (for instance this one; but many more if you google “wordpress next/previous post in same category”) and in the past it could be done by modifying the navigation.php and adding true to the two functions:

    $prev_post = get_previous_post(true);
    $next_post = get_next_post(true);

    So, how can I do the same now with a FSE site? Cause I can’t find any PHP files where to edit this. What is the recommended best practice?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • So, how can I do the same now with a FSE site? Cause I can’t find any PHP files where to edit this. What is the recommended best practice?

    Hi @sirawesome you can add the code to your site using the Code Snippet plugin. This plugin allows you to add PHP code to your site, I am not quite sure if the code you have will work on your site.
    However, I tried the code shown here and it’s working as expected on my test site.

    Thread Starter sirawesome

    (@sirawesome)

    Hi @thelmachido ; thank you very much for your answer.
    I have taken a look at code snippet and at the link you shared, but I don’t understand how to test this code out in the Twenty Twenty-Three theme.

    Your example says to paste this code in the function.php (the author uses Astra but says it should work on other themes too) but as I wrote, these newer FSE themes don’t have those function.php (and all the other PHP files) anymore. Or at least, I can’t find them… ??

    Or, did you implement this code with the Code Snippet plugin? If that’s the case, could you share a little bit more info on how you did it?

    Thanks!

    Or, did you implement this code with the Code Snippet plugin? If that’s the case, could you share a little bit more info on how you did it?

    Hi @sirawesome yes the TT3 theme structure is different from the classic theme, the files are also different which is why you can’t find a functions.php.
    I was suggesting using the plugin to add the code. If you go to Plugins > Add New search for Code Snippet. You can also download the plugin from here.

    Once the plugin is active, you should be able to see a section called Snippets from your dashboard. Opening Snippets > Add New will take you to a page for adding custom code. Save and activate the added code once done.

    Thread Starter sirawesome

    (@sirawesome)

    I wanted to say that this worked!

    I meant to try this earlier but life happened and I was delayed but anyhow creating a snippet with the PHP stated in the first link worked . I chose the option to “Only run on site front-end” and immediately the previous/next links were only showing items from the same category.

    Thanks!

    Moderator Kathryn Presner

    (@zoonini)

    Glad to hear you got this sorted, thanks for returning to share the good news!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Next and Previous blog navigation within the same category’ is closed to new replies.