• Resolved garnergrows

    (@garnergrows)


    I have seen this question asked and solved for many other themes, but can’t seem to find the proper configuration for Dyad 2. I want to restrict the Next/Previous Post links at the bottom of each post so that they only link to other posts in the same category.

    I have my posts grouped into 3 basic categories: Blog, Recipes, and Photo Galleries. I want the next/previous post links at the bottom of each post to only direct visitors to posts within the same category. You can see a good example of this at: https://test.garnergrows.com/baked-kale-chips/. The Next post link goes to another recipe, but the Previous post goes to a Blog entry which is less than desirable!

    I have setup a staging copy of my site as well as a child theme for Dyad 2 so that I can safely edit php files, but I am unsure exactly where and how to edit. I (believe) I have found the code for these links in the “single.php” file. Other answers to the question have indicated that: ‘in_same_term’ must be set to “true”, but I am unsure exactly how and where to do this.

    Any help would be appreciated. Thanks!

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    As a rule we don’t provide support for custom code changes like this, but I was curious and wanted to see what this would involve.

    It looks like Dyad-2 uses the_post_navigation to generate those links (code reference), and you’ll find that function called in single.php

    That function accepts an array as argument, and that array can include arguments to limit the links to a specific taxonomy.

    So in single.php, modify the the_post_navigation function to look like this:

    <?php
    			the_post_navigation( array(
    				'prev_text' => '<div class="nav-previous"><span class="nav-subtitle">' . esc_html__( 'Previous Post', 'dyad-2' ) . '</span> <span class="nav-title">%title</span></div>',
    				'next_text' => '<div class="nav-next"><span class="nav-subtitle">' . esc_html__( 'Next Post', 'dyad-2' ) . '</span> <span class="nav-title">%title</span></div>',
    				'taxonomy' => 'category',
    				'in_same_term' => true,
    			) );
    			?>

    In other words, just adding the taxonomy and in_same_term arguments to the array.

    This change works for me on a test site, so should be all you need. But if it doesn’t work, please ask for more advice in the Developing with WordPress forum instead:

    https://www.ads-software.com/support/forum/wp-advanced/

    Thread Starter garnergrows

    (@garnergrows)

    Thanks KokkieH, not only did your solution do the trick, but I have bookmarked the link you provided to the Developing with WordPress forum for future reference!

    Thanks for letting me know it worked ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dyad 2: Limit Next/Previous Post to one Category’ is closed to new replies.