Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1001628
    frix00
    Participant

    Hi,

    We’d like to have the sidebar displayed on the left hand side when users are in the Shop (WooCommerce) section, but have it on the right hand side in the Blog section.
    Currently, the theme customiser offers only one radio buttion option to have “content left, side bar right” or “content right, sidebar left” and o option to set this only for the Blog, or only for the Shop.

    We also have two different sidebars for these two sections: the Shop uses the normal main sidebar, with widgets related to commerce (product filters, etc) while the Bolg has its own Sidebar, with widgets such as latest posts, etc.

    See URLs :
    https://www.vinoa.co.uk/shop/
    https://www.vinoa.co.uk/magazine/

    Is there a simple way of handling this via some code in functions.php (or elsewhere) ?

    Thanks !

    Greg

    #1001817
    Rahul
    Moderator

    Hi Greg,

    I see, please add this code at your child theme’s functions.php

    if ( ! function_exists( 'x_get_content_layout' ) ) :
      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 = 'sidebar-content';
            } else {
              $layout = 'sidebar-content';
            }
          } elseif ( x_is_product() ) {
            $layout = 'sidebar-content';
          } 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;
        }
    
        return $layout;
    
      }
    endif;

    Then just set your sidebar to right, and the code will handle the shop sidebar to left.

    Thanks!

    #1005520
    frix00
    Participant

    Amazing – that’s almost perfect. It works in getting me the side bar on the right on individual posts, but on the category landing pages, the sidebar is still on the left – any ideas ?

    Thanks

    Greg

    #1005529
    frix00
    Participant

    Not to worry, I edited your code to add

    elseif ( is_category(‘magazine’) ) {
    $layout = ‘content-sidebar’;
    }

    #1005530
    frix00
    Participant

    Thanks a lot !!

    #1005535
    Joao
    Moderator

    You are welcome.

    Let us know if you need help with anything else.

    Joao

    #1020750
    jclay12345
    Participant

    I just tried this and it worked for me, but now my product pages have a sidebar and I would like those to be full width. Any ideas?

    I tried editing this line

    elseif ( x_is_product() ) {
            $layout = 'sidebar-content';
          }

    to

    elseif ( x_is_product() ) {
            $layout = 'full-width';
          }

    but that doesn’t seem to work

    #1020805
    jclay12345
    Participant

    Sorry, that change worked. it must’ve been a problem with caching.

    #1021384
    Friech
    Moderator

    Cool, should you require any further assistance with X|THEME and Cornerstone, please feel free to get in touch with us.

    Cheers!

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