Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1063030
    ArtOfSpring
    Participant

    Hi there,

    I’m using an Integrity child theme for a WooCommerce online shop.
    I activated breadcrumbs to enable the navigation arrows on a product page.
    Also I set up product categories (Sake, Whisky, Accessoires).

    But using the arrows to navigate between the different products it seems to be a random order(?).
    This is a “Whisky”: http://stage3.art-of-spring.marketing/produkt/houga/
    After navigating to the right a “Sake” shows up: http://stage3.art-of-spring.marketing/produkt/ginshu-ginjo/
    Then one more Sake and the next in line is an “Accessoire”.

    Can I customize the order? I want to achieve that a product of one category e.g. “Sake” won’t be followed by a product of another category. Any idea?

    Thank you

    #1063139
    Paul R
    Moderator

    Hi,

    To restrict the navigation to the same category, you can add this in your child theme’s functions.php file.

    
    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 );
      $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
      }
    
    

    The items are ordered from latest to oldest so you can modify the date to order it.

    Hope that helps.

    #1063215
    ArtOfSpring
    Participant

    Hi there,

    I added the code to my child theme’s function.php file but now the arrows disappeared.

    #1063219
    Paul R
    Moderator

    Hi,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1063373
    ArtOfSpring
    Participant
    This reply has been marked as private.
    #1064261
    Lely
    Moderator
    This reply has been marked as private.
    #1064477
    ArtOfSpring
    Participant
    This reply has been marked as private.
    #1064657
    Paul R
    Moderator

    Hi,

    I tried to login to ftp but there are several directories.

    May I know which directory your site points to.

    Thanks

    #1064701
    Lely
    Moderator

    Hi There,

    As you are targeting products, get_adjacent_posts() also require a taxonomy slug, i.e., product_cat for product post type. Please update above 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>';
      }
      if ( x_is_product() ) {
        $taxonomy = 'product_cat';
      } else {
        $taxonomy = 'category';
      }  $is_ltr    = ! is_rtl();
      $prev_post = get_adjacent_post( true, '', false,$taxonomy );
      $next_post = get_adjacent_post( true, '', true,$taxonomy );
      $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 this helps.

    #1064793
    ArtOfSpring
    Participant
    This reply has been marked as private.
    #1064794
    ArtOfSpring
    Participant

    Hi Lely,

    the updated code seems to work!

    Thank you

    #1064896
    Paul R
    Moderator

    Glad to know. Have a great day!

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