Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #303040

    thisisbbc
    Participant

    Hi,

    I would like to be able to display a sidebar on all products archive (category or tags). I’ve noticed that the tags/categories are mixed between posts and products in the Sidebar menu.

    Is there anything I can do to hook a sidebar to the is_product_category() function?

    Regards,
    Bastien

    #303364

    Paul R
    Moderator

    Hi Bastien,

    You can try adding the code below in your child theme’s functions.php file

    
      function x_get_content_layout() {
    
        $content_layout = x_get_option( 'x_layout_content', 'content-sidebar' );
    
        if ( $content_layout != 'full-width' ) {
          if ( is_home() ) {
            $opt    = x_get_option( 'x_blog_layout', 'sidebar' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          } elseif ( is_singular( 'post' ) ) {
            $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
            $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
          } elseif ( x_is_portfolio_item() ) {
            $layout = 'full-width';
          } elseif ( x_is_portfolio() ) {
            $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
            $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
          } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
            $layout = 'content-sidebar';
          } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
            $layout = 'sidebar-content';
          } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
            $layout = 'full-width';
          } elseif ( is_archive() ) {
            if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
              $layout = 'content-sidebar';
            } else {
              $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            }
          } elseif ( x_is_product() ) {
            $layout = 'full-width';
          } elseif ( x_is_bbpress() ) {
            $opt    = x_get_option( 'x_bbpress_layout_content', 'sidebar' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          } elseif ( x_is_buddypress() ) {
            $opt    = x_get_option( 'x_buddypress_layout_content', 'sidebar' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          } elseif ( is_404() ) {
            $layout = 'full-width';
          } else {
            $layout = $content_layout;
          }
        } else {
          $layout = $content_layout;
          if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
             $layout = 'content-sidebar';
          }
        }
    
        return $layout;
    
      }
    

    Hope that helps.

    #303628

    thisisbbc
    Participant

    Hi guys,

    Thanks for the answer. However I’m not too sure how to use this. I have created a sidebar named “WooCommerce”, how am I supposed to tell the function to use this sidebar on the category/tag archive? What I meant initially isn’t that there was no sidebar in our product archive, there is one, it’s just that we can only tell our sidebar to display on the “Shop” page and there are no options for “Product archive”

    I have tried to replace “content-sidebar” with the ID of the sidebar we want to put, “ups-sidebar-woocommerce” but it didn’t work 🙁

    Regards,
    B

    #303959

    Zeshan
    Member

    Hi B,

    You can assign your custom sidebar to a product category or archive page by selected it under All Taxonomies section (see: http://prntscr.com/7hr0yj).

    Thanks!

    #304266

    thisisbbc
    Participant

    Hi guys,

    Thank you for your answer. However I already knew about that. The problem with this is that All Taxonomies really is everything, posts and products mixed together.

    Moreover you can’t display a default sidebar for all product categories, or all product tags. This option does not exist. Hence I was wondering if it was possible to hook a sidebar to “is_product_category()” function.

    Thank you.

    #304648

    Paul R
    Moderator

    Hi Bastien,

    In that case, 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.

    #305456

    thisisbbc
    Participant
    This reply has been marked as private.
    #305978

    Zeshan
    Member

    Hi B,

    As the name suggests, All Taxonomies panel displays taxonomies from all post types. You can simply search through the panel and select your product categories and tags.

    If you want to show a custom sidebar to all of your product tags and categories, you can use following workaround. While custom development is outside the scope of support, I could point you in the right direction with the understanding that it would ultimately be your responsibility to take it from here.

    Copy the file wp-content/themes/x/framework/views/icon/wp-sidebar.php in your child theme’s folder /framework/views/icon/, open the copied file in a text editor and replace entire code with following :

    <?php
    
    // =============================================================================
    // VIEWS/ICON/WP-SIDEBAR.PHP
    // -----------------------------------------------------------------------------
    // Sidebar output for Icon.
    // =============================================================================
    
    ?>
    
    <?php if ( x_get_content_layout() != 'full-width' ) : ?>
    
      <aside class="x-sidebar nano" role="complementary">
        <div class="max width nano-content">
          <?php if ( is_product_category() || is_product_tag() ): ?>
            <?php dynamic_sidebar( 'custom-product-tag-category-sidebar' ); ?>
          <?php elseif ( get_option( 'ups_sidebars' ) != array() ) : ?>
            <?php dynamic_sidebar( apply_filters( 'ups_sidebar', 'sidebar-main' ) ); ?>
          <?php else : ?>
            <?php dynamic_sidebar( 'sidebar-main' ); ?>
          <?php endif; ?>
        </div>
      </aside>
    
    <?php endif; ?>
    

    Replace custom-product-tag-category-sidebar with your custom sidebar ID.

    Thanks!

    #306327

    thisisbbc
    Participant

    Hi guys!

    Thank you a lot for the provided snippet. I added our custom sidebar ID and it worked out of the box 🙂

    Really appreciate your help!

    Kind regards,
    B

    #306657

    Lely
    Moderator

    You’re welcome B!

    Cheers!
    X