Custom Sidebar except for home page

Hi,

I use code, all is ok but I want to sidebar on left side. Please help me.

Tahnk you.

Code:

add_filter( ‘ups_sidebar’, ‘x_woocommerce_sidebar’ );
function x_woocommerce_sidebar($sidebar){
if( is_product() || is_shop() || is_cart() || is_checkout() || x_is_product_category()){ //is_shop() is_woocommerce() ||
return ‘ups-sidebar-woocommerce’;
}
return $sidebar;
}
function x_get_content_layout() {
$content_layout = x_get_option( ‘x_layout_content’ );
if ( $content_layout != ‘full-width’ ) {
if ( is_home() ) {
$opt = x_get_option( ‘x_blog_layout’ );
$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() ) {
$opt = x_get_option( ‘x_woocommerce_shop_layout_content’ );
$layout = ( $opt == ‘sidebar’ ) ? $content_layout : $opt;
} else {
$opt = x_get_option( ‘x_archive_layout’ );
$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’ );
$layout = ( $opt == ‘sidebar’ ) ? $content_layout : $opt;
} elseif ( x_is_buddypress() ) {
$opt = x_get_option( ‘x_buddypress_layout_content’ );
$layout = ( $opt == ‘sidebar’ ) ? $content_layout : $opt;
} elseif ( is_404() ) {
$layout = ‘full-width’;
} else {
$layout = $content_layout;
}
} else {
$layout = $content_layout;
}
if( is_product() || is_shop() || is_cart() || is_checkout() || x_is_product_category()){ //is_woocommerce() ||
return ‘content-sidebar’;
}
return $layout;
}

Hey @matuskm,

What is the page you want the sidebar to be on the left? Please give us context so we can provide an accurate answer.

Thanks.

On this page: https://qootsk.kms-pt.sk/kategoria-produktu/s-chybou-krasy/ are categories in right but I want categories to left side on all pages.

Hi @matuskm,

Thank you for the clarification.

Go to Theme Options > Layout and Design > Content Layout : Sidebar Left, Content Right. This setup will make your sidebar to the left by default. Then the exception for that setup, are the last part of the code you have above.

if( is_product() || is_shop() || is_cart() || is_checkout() || x_is_product_category()){ //is_woocommerce() ||
return 'content-sidebar';
}
return $layout;
}

That code above says that all those pages inside the filter, layout should show sidebar on the right. Remove any page filter where you want the default sidebar setup.

Hope this helps.

Hi,

I have Content Layout: Sidebar Left, Content Right but not working.

Add in class x-main left and add class in sidebar x-sidebar right. I don’t understand…

Hi @matuskm,

It’s due to your custom code, this represents Content Left, Sidebar Right

return 'content-sidebar';

To make it Sidebar Left, Content Right then please change it to

return 'sidebar-content';

Hope this helps.

@Rad

Well done! It’s working.

Thank you!

Hi,

I have problem. Left sidebar on Chrome sometimes hidden.

https://qootsk.kms-pt.sk/kategoria-produktu/hodinky/

Hi @matuskm,

It’s due to this custom CSS

.x-sidebar {
    width: 10%;
    position: fixed;
    z-index: 999;
    background: #ffffff;
}

It doesn’t sync well with other layout structure since it’s floating. You could remove it, or make it specific to screen resolution. Example,

@media ( min-width: 1024px ) {
.x-sidebar {
    width: 10%;
    position: fixed;
    z-index: 999;
    background: #ffffff;
}
}

Though, I’m not sure which screen you’re checking it with so I only assume it’s 1024px (Portrait tablet size and above)

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.