Shop Sidebar Position based on Category - by thisisbolo

This topic has 5 replies, 2 voices, and was last updated 6 years, 10 months ago ago by Olga Barlow

  • Avatar: thisisbolo
    thisisbolo
    Participant
    January 7, 2018 at 05:44

    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.

    4 Answers
    Avatar: thisisbolo
    thisisbolo
    Participant
    January 7, 2018 at 18:53

    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 🙂

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    January 9, 2018 at 12:13

    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

    Avatar: thisisbolo
    thisisbolo
    Participant
    January 9, 2018 at 18:51

    @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

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    January 10, 2018 at 14:23

    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

  • Viewing 5 results - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.