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.

My Wordpress theme is using some code in the "sidebar.php" file that tells it that some pages should always use the default sidebar. This was fine until I found that each and every custom taxonomy (example: "taxonomy-mountains.php") page is defaulting to this default sidebar.

I thought about catching this with is_taxonomy(), but that's deprecated and won't work. Any better programmers out there with an idea of how I could fix this now. Something like if(is_taxonomy('mountains')){} would've worked fine. Below code is an excerpt, if you think something is missing let me know.

//Default sidebar
$selected_sidebar_replacement = 'Sidebar Widgets';

//If is page or single
if(is_singular()){
global $wp_query;
$post = $wp_query->get_queried_object();
$selected_sidebar_replacement = get_post_meta($post->ID, 'sbg_selected_sidebar_replacement', true);

//If default selected
if($selected_sidebar_replacement == '0' || $selected_sidebar_replacement == ''){
$selected_sidebar_replacement = 'Sidebar Widgets';
                    }

// Reset the global $the_post
wp_reset_query();

                }
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

The function that replaces is_taxonomy() is named taxonomy_exists(). Than there's also is_tax() and is_tag() that check if the query is for a taxonomy archive page.

EDIT

$selected_sidebar_replacement == '0' || $selected_sidebar_replacement == '' won't work. You're not checking the type.

Better do it like this:

if ( ! $selected_sidebar_replacement OR emtpy( $selected_sidebar_replacement ) )
share|improve this answer
    
Thanks @kaiser, however I don't know how to use this to display for example the sidebar "gear" when I'm in the taxonomy "product-brand". Below doesn't work. if(is_tax( 'product-brand' )){ $selected_sidebar_replacement = 'Gear'; } –  WouterB Mar 27 '12 at 15:00
    
See Edit (filler) –  kaiser Mar 27 '12 at 15:47
    
You're talking in riddles... "you can't change the taxonomy on your custom taxonomy pages"? Change? How? What? btw: ↑ you've been checking against '0' which is a string. That shouldn't happen when selecting a string... –  kaiser Mar 27 '12 at 16:29
    
TYPO:"The issue I'm having is that I can't change the SIDEBAR on my custom taxonomy pages." Yes I have been checking against '0', and while it isn't a string, it is working, and your suggestion isn't. I'll look in to that later, but first I really need to figure out how to display different sidebars when I'm on different custom taxonomies. –  WouterB Mar 27 '12 at 16:43
    
@WouterB As you marked it as solution: What exactly was the solution? –  kaiser Mar 28 '12 at 11:09
add comment

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.