Tagged: x
-
AuthorPosts
-
October 26, 2016 at 4:06 am #1231132
steinmacherParticipantHello,
I am trying to get the prev/next arrows to only change within a category in my shop. I used this code in the functions.php of the child theme:
function x_entry_navigation() {
$stack = x_get_stack();
if ( $stack == ‘ethos’ ) {
$left_icon = ‘<i class=”x-icon-chevron-left”></i>’;
$right_icon = ‘<i class=”x-icon-chevron-right”></i>’;
} else {
$left_icon = ‘<i class=”x-icon-arrow-left”></i>’;
$right_icon = ‘<i class=”x-icon-arrow-right”></i>’;
}$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 ) : ?>
” title=”<?php __( ‘Previous Post’, ‘__x__’ ); ?>” class=”prev”>
<?php echo $prev_icon; ?>
<?php endif; ?><?php if ( $next_post ) : ?>
” title=”<?php __( ‘Next Post’, ‘__x__’ ); ?>” class=”next”>
<?php echo $next_icon; ?>
<?php endif; ?></div>
<?php
}
But as soon as I implement it, the arrows are gone on the site. If I change the get_adjacent_post to (TRUE,,…) in the main theme, the same results happen – arrows are gone. I tried setting up a development site with only the theme and WooCommerce active, added the function to the child theme – and again the arrows vanished.
Do you know what I need to do to get the arrows working in my Shop?
Thanks in advance,
MatthiasOctober 26, 2016 at 5:27 am #1231234
Paul RModeratorHi Matthias,
You can try this code instead.
function x_entry_navigation() { $stack = x_get_stack(); if ( $stack == 'ethos' ) { $left_icon = '<i class="x-icon-chevron-left" data-x-icon=""></i>'; $right_icon = '<i class="x-icon-chevron-right" data-x-icon=""></i>'; } else { $left_icon = '<i class="x-icon-arrow-left" data-x-icon=""></i>'; $right_icon = '<i class="x-icon-arrow-right" data-x-icon=""></i>'; } $is_ltr = ! is_rtl(); $prev_post = get_adjacent_post( false, '', false ,'category'); $next_post = get_adjacent_post( false, '', true,'category' ); $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 }Hope that helps.
October 26, 2016 at 6:09 am #1231288
steinmacherParticipantHi!
Thanks for the quick reply. I implemented this code, but unfortunately it doesn’t do anything. The arrows show up, but switch between categories when at the end of one.
I also think that the $taxonomy only gets called if $in_same_term is set true. https://codex.wordpress.org/Function_Reference/get_adjacent_postDo you have any other ideas maybe? 😉
October 26, 2016 at 7:06 am #1231352
Paul RModeratorHi,
Yes, it should be true.
Kindly change the code to this.
function x_entry_navigation() { $stack = x_get_stack(); if ( $stack == 'ethos' ) { $left_icon = '<i class="x-icon-chevron-left" data-x-icon=""></i>'; $right_icon = '<i class="x-icon-chevron-right" data-x-icon=""></i>'; } else { $left_icon = '<i class="x-icon-arrow-left" data-x-icon=""></i>'; $right_icon = '<i class="x-icon-arrow-right" data-x-icon=""></i>'; } $is_ltr = ! is_rtl(); $prev_post = get_adjacent_post( true, '', false ,'category'); $next_post = get_adjacent_post( true, '', true,'category' ); $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 }If that doesn’t help, please provide us wordpress admin login private reply.
Thanks
October 26, 2016 at 8:41 pm #1232433
steinmacherParticipantThis reply has been marked as private.October 27, 2016 at 12:42 am #1232679
RadModeratorHi there,
Please try product_cat instead of category.
$prev_post = get_adjacent_post( true, '', false ,'product_cat'); $next_post = get_adjacent_post( true, '', true,'product_cat' );Products aren’t the same as post, it uses different taxonomy.
Thanks!
October 27, 2016 at 1:04 am #1232690
steinmacherParticipantThat was it. Thank you so much!
October 27, 2016 at 1:17 am #1232703
FriechModeratorYou’re more than welcome, glad we could help.
Cheers!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1231132 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
