This topic has 5 replies, 2 voices, and was last updated 6 years, 11 months ago ago by Olga Barlow
Where can I add an conditional in child theme to change the layout of the shop sidebar position based on a certain category term?
<?php if ( has_term ( 'Category1', 'product_cat')) {
// No sidebar on shop page
} elseif ( has_term ( 'Category1', 'product_cat')) {
// Show sidebar on left
} else {
//everything else
}
On another note, this should be super cool to have as a theme function. I haven’t seen a theme with this. It should be as simple as having an include/exclude categories section on the theme options.
I think I figured this out. I’ve undercovered 2 different approaches. Adding in
Approach 1:
Edit the ‘archive-product.php’ in child theme
<?php
if ( has_term ( 'Category-Term', 'product_cat') ) {
// Edit the 'archive-product.php' to remove the sidebar
} else {
// Edit the 'archive-product.php' to remove the sidebar to do something else
}
?>
Approach 2 (this requires a bit more CSS editing)
Edit style.css in child theme
.term-Category-Term .content-page {width: 1170px !important;}
.term-Category-Term .sidebar {display: none;}
.term-Category-Term .col-md-push-3 {left: unset}
.term-Category-Term .col-md-9 {width: 100%;}
It looks like for the CSS approach, it’d have to be for every term so if the category you’re selecting has sub-categories, then those category terms need to be selected for ‘Category-Term’
If you folks on the support forum have a better approach, I’m open 🙂
Hello,
Do you want to show the sidebar on the shop page but hide for some category or hide the sidebar on the shop page and show for some category only? Because code will be different in these 2 variants.
Or it would be better to add the sidebar position option for every category in categories settings, for example http://prntscr.com/hxziax ?
Regards
@Olga, I actually don’t see this option in my category section all i have is
parent category
description
display type
thumbnail
custom page heading
description after content
Hello,
Yes, there is no such option at present, I just sent that screenshot to clarify what exactly you want to implement and then our developers will try to add the option. So, would you like to have the option for the category? Do you want to hide/change the position of the sidebar for some categories only and should it be the individual option for every category or did you mean some global option?
Regards
Tagged: category, position, shop sidebar, woocommerce, wordpress
You must be logged in to reply to this topic.Log in/Sign up