Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1231132
    steinmacher
    Participant

    Hello,

    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,
    Matthias

    #1231234
    Paul R
    Moderator

    Hi 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.

    #1231288
    steinmacher
    Participant

    Hi!
    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_post

    Do you have any other ideas maybe? 😉

    #1231352
    Paul R
    Moderator

    Hi,

    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

    #1232433
    steinmacher
    Participant
    This reply has been marked as private.
    #1232679
    Rad
    Moderator

    Hi 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!

    #1232690
    steinmacher
    Participant

    That was it. Thank you so much!

    #1232703
    Friech
    Moderator

    You’re more than welcome, glad we could help.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1231132 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>