Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to load different right and left sidebars depending on a custom taxonomy term. If there is no term from this custom taxonomy, then just load the default sidebar.php and sidebar-right.php files.

For example, the alternate sidebars would be something like:

  • sidebar-carrots.php and sidebar-carrots-right.php
  • sidebar-apples.php and sidebar-apples-right.php
  • etc.

I know about the Widget Logic plugin, but I want more control and need to load completely different sidebar template files.

I'm sure that I could throw together something messy and functional, but I would like to know what is the best way to set that up.

share|improve this question

1 Answer 1

There are 2 options that comes in mind

First use a conditional statement is_tax('taxonomy-name', 'term name').

is_tax('fruits', 'apples'){
    get_sidebar('apples');
    get_sidebar('apples-right');
} if is_tax('fruits', 'oranges') {
    get_sidebar('oranges');
    get_sidebar('oranges-right');
}

Or, the second option, use a different template file instead.

taxonomy-fruits-apples.php should use

    get_sidebar('apples');
    get_sidebar('apples-right');

taxonomy-fruits-oranges.php should use

    get_sidebar('oranges');
    get_sidebar('oranges-right');

Hope this help

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.