Is there a way to alter the way navigation arrows for articles (both blog and woocommerce items) behave, so they wont take me to the next article based on date of entry but instead the next article in the same category, regardless of when it was created?
Hi Boris,
Thanks for reaching out.
It should already work like that, the code responsible for that is this
function x_entry_navigation() {
$stack = x_get_stack();
if ( $stack == 'ethos' ) {
$left_icon = '<i class="x-icon-chevron-left" data-x-icon-s=""></i>';
$right_icon = '<i class="x-icon-chevron-right" data-x-icon-s=""></i>';
} else {
$left_icon = '<i class="x-icon-arrow-left" data-x-icon-s=""></i>';
$right_icon = '<i class="x-icon-arrow-right" data-x-icon-s=""></i>';
}
$is_ltr = ! is_rtl();
$prev_post = get_adjacent_post( false, '', false );
$next_post = get_adjacent_post( false, '', 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
}
The get_adjacent_post( ) https://codex.wordpress.org/Function_Reference/get_adjacent_post has 4th parameter called $taxonomy, and by default it’s going to be category if there is no supplied taxonomy parameter.
You can copy that code and modify it and place it in your child theme’s functions.php. Though, I’m not sure what else to modify since the code should already do that. But of course, it will pick the next or previous entry order by date but filtered by category.
Thanks!
Hi Rad
Thanks for your reply!
So, I inserted the code into the child theme functions.php.
Unfortunately it still doesnt work. Its still only following creation date and as such jumps wildly between categories back and forth.
With the Blog its a nuisance but in Woocommerce its downright bad when the Next Item arrow (in the same category, as one would expect) jumps to an entirely unrelated item in a completely different category.
Frankly, what I’m looking for is Next/Previous functionality that is strictly limited to the same category. When it reaches the last entry or item, it should go back to the first one in the same category. Is that even possible?
Thanks for your help.
Hi Boris,
Pasting the same code will not work if you’ll not add your customization. I just provided it so you could customize that original code. Plus, the code already default to category taxonomy, but please try this one
From the above code, please replace this two lines
$prev_post = get_adjacent_post( false, '', false );
$next_post = get_adjacent_post( false, '', true );
With this
$taxonomy = is_singular('product') ? 'product_cat' : 'category';
$prev_post = get_adjacent_post( false, '', false, $taxonomy );
$next_post = get_adjacent_post( false, '', true, $taxonomy );
For further customization, I recommend contacting a developer. All of those codes uses default options based on Wordpress standard(as per provided link).
Thanks!
Thanks again but that doesnt change anything either.
I will just disable the arrows and forget out it.
Hi Boris,
I just tried them and it’s working on my end, plus, it’s Wordpress provided function (get_adjacent_post()). Sure, you can also remove/hide it too.
Thanks!
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.