Cynthia
Cynthia

Reputation: 5403

How to make a wordpress sidebar conditional?

I'm working on a Wordpress site that uses the Reason theme from Themeforest. I have been able to work out all issues except for two, one of which is the basis for this question.

The theme comes with a sidebar, but I want to disable it unless the user is on one of two category pages OR on a post in one of those two categories.

Here is the code from page.php that calls the sidebar:

<div class="four columns sidebar">          
    <?php dynamic_sidebar( 'default-widget-area' ); ?>  
</div>

Any help would be much appreciated...

Thanks!

Cynthia

Upvotes: 0

Views: 1294

Answers (2)

Alex Phelps
Alex Phelps

Reputation: 11

Checkout WooSidebars - http://wordpress.org/plugins/woosidebars/

This is a great plugin that has all kinds of logic that should fit your use case. You can create multiple widget areas in sidebars a on pages, page templates, and so on.

Upvotes: 0

RRikesh
RRikesh

Reputation: 14381

You have some functions that can help you with that:

  1. in_category() should be used when the user is on a post of the category (single.php)
  2. is_category() should be used when the user is on a category page (category.php)

From WordPres Codex,

in_category( array( 1,2,3 ) ) 
    Returns true if the current post is in either category 1, 2, or 3.

Upvotes: 1

Related Questions