简体   繁体   中英

Wordpress - Jigoshop conditional statements

I'm using Jigoshop and Wordpress.

My main goal is to load a different sidebar in different product categories.

I've managed to do this by using :

function jigoshop_get_sidebar() {

    if(is_shop()) get_sidebar('shop'); if ( is_product_category('poura'))
        get_sidebar('cigars');
}

in my functions.php file.

Now the issue is that I have some products that are in not just one category, so when I try doing something like this:

function jigoshop_get_sidebar() {
    if(is_shop()) get_sidebar('shop'); if ( is_product_category('poura'))
           get_sidebar('cigars'); if ( is_product_category('cigarillos'))
           get_sidebar('shop');
}

I now get both of the sidebars ('cigars','shop') because some products share both the category 'poura' and 'cigarillos'.

How is it possible to have just one sidebar under these circumstances?

Thanks again for any help!

An "else if" statement is not resolving your problem?

Basically what i meant was the you need a switch case not a lot of different ifs.

function jigoshop_get_sidebar() { 
    if(is_shop()) 
           get_sidebar('shop');
    elseif ( is_product_category('poura'))
           get_sidebar('cigars'); 
    elseif ( is_product_category('cigarillos'))
           get_sidebar('cigarillos');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM