• Resolved mislavjuric

    (@mislavjuric)


    Hello there WordPress crew,

    I would like to modify my website so that the next and previous links on individual posts lead to the posts from the same category. How can I do so in TwentyTwenty?

    Thank you in advance!

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Howdy!

    One way I can think of would be to create a child theme ( if you haven’t already ) and change the template file to use the additional parameter for the function next_post_link() and the previous_post_link()

    Each of those is documented here:
    https://developer.www.ads-software.com/reference/functions/next_post_link/
    https://developer.www.ads-software.com/reference/functions/previous_post_link/

    I know, probably not the greatest reply but that might give you an idea of what to do. I’m not sure what your comfort level is as far as code so I did hesitate a little on providing a full blown tutorial. I’m sure there might be one out in the wild though ??

    Let us know if you have follow up questions

    Thread Starter mislavjuric

    (@mislavjuric)

    Hey @jcastaneda,

    thank you for responding.

    I understand that I need to set the in_same_term parameter on both next_post_link() and previous_post_link() to true if I want to enable that functionality. What I don’t know is how to create a child theme.

    I would not like to experiment with WordPress tutorials from the wild because I may break my website following them.

    Could you provide a full-blown, step-by-step tutorial on how to do this? I think it’d be best for me and anyone looking for this later on.

    Best,
    Mislav

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    The quick and dirty:

    1. Make a child theme.
    2. Copy the file that uses the pagination functions ( https://themes.trac.www.ads-software.com/browser/twentytwenty/1.4/template-parts/navigation.php ) to your child theme making sure it also matches the same folder structure
    3. Change the corresponding parts.
    4. Save the file
    5. Make some coffee/tea.

    As much as I would love to write it all out, as I said, there are other tutorials as well. Most will go over how to do those steps as well. There are plugins that can create child themes in the wild and in the repo.

    Thread Starter mislavjuric

    (@mislavjuric)

    Hey @jcastaneda,

    I did it. I followed this tutorial to make a child theme and I get_next_post() and get_previous_post() functions in navigation.php file. I made sure to have the same directory structure as in the original theme.

    For someone that doesn’t code, the two lines I had to modify look like this after modification (lines 10 and 11):

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

    Thank you @jcastaneda! I do have to admit that I skipped the 5th step. ??

    Best,
    Mislav

    • This reply was modified 4 years, 3 months ago by mislavjuric.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘TwentyTwenty: Post page: next and previous link from same category’ is closed to new replies.