Post Navigation within Category (updates?)

Hi team,
I’d like to recall on this topic as it looks a recurring need.

The need is plain easy: see the buttons prev/next, I don’t want them to go beyond category (or subcategory).

image
So if I land on a given product’s page, I will be able to explore the rest of the range in the present category/subcategory.

The elements depicted are enclosed in a Section providing Current Post Terms = Category.

The blurred (can’t disclose) are Breadcrumbs element and Term List.
Term List shows Category/Subcategory as a complementary breadcrumbs.

With this I mean that the Categories are loaded and known, I just need the Nav buttons to be aware of present product category boundaries. If this product has 3 brother products, I won’t be able to navigate out of this 4 products until I browse another category/subcategory.

I know that this navigation buttons were probably thought to reach A-Z in purpose, I share the point.
But customer wants this limitation, which I understand as well. For precision SEO, must admit this is a nice-to-have.

The threads I found are quite old now; Is there any modern cheat for this, within support scope?

Thank you!

Hello Ricard,

We do not have that feature as of this moment. I will take note of your feedback and forward it to our developers. This has been added as a feature request before. I will ask for a follow up on this.

Best Regards.

Thanks for considering, have a nice week.

You are most welcome, Ricard.

4 years later this still would be a great and useful feature. :slight_smile:

1 Like

Thank you for the update.

In the meantime, try to override the x_entry_navigation function in the functions.php file:

function x_entry_navigation() {
    $stack = x_get_stack();

    if ($stack == 'ethos') {
        $left_icon  = x_icon_get("f053", "x-icon-chevron-left");
        $right_icon = x_icon_get("f054", "x-icon-chevron-right");
    } else {
        $left_icon  = x_icon_get("f060", "x-icon-arrow-left");
        $right_icon = x_icon_get("f061", "x-icon-arrow-right");
    }

    $is_ltr    = !is_rtl();
    $prev_post = get_adjacent_post(true, '', false);
    $next_post = get_adjacent_post(true, '', true);

    $prev_icon = ($is_ltr) ? $left_icon : $right_icon;
    $next_icon = ($is_ltr) ? $right_icon : $left_icon;
    ?>

    <div class="x-nav-articles">
        <?php if ($prev_post) : ?>
            <a href="<?php echo get_permalink($prev_post); ?>" title="<?php __('Previous Post', '__x__'); ?>" class="prev">
                <?php echo $prev_icon; ?>
            </a>
        <?php endif; ?>

        <?php if ($next_post) : ?>
            <a href="<?php echo get_permalink($next_post); ?>" title="<?php __('Next Post', '__x__'); ?>" class="next">
                <?php echo $next_icon; ?>
            </a>
        <?php endif; ?>
    </div>

<?php
}

This sets the first parameter $in_same_term of the get_adjacent_post function to true , which filters posts based on the same category or terms.

https://developer.wordpress.org/reference/functions/get_adjacent_post/

If you need help with modifications like this, please check out our One service.

Also, not sure if you heard but we just launched SiteDrive this week. It allows you to send any file to any site, anytime with real time syncing and actually delivers files directly the end app thanks to integrations. Really cool product for anyone who has client sites or manages more than one website and needs to move files around. Check it out when you get a second, and hope you have a nice day!

Let us know if you need more info.

There’s always a chance I did some mistake, but tried several times and could not contain the navigation within category. Also changing stack from Ethos to Integrity. Nothing broken, but no changes on sight. Thanks for the workaround anyway.

You are most welcome @seofreelance