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 can't get any help on the buddypress forums so I'm going to ask it here. I'm trying to use conditional tags so I can have a different sidebar for the profile page than the activity page. For some reason the way I have it setup in my sidebar.php still returns the default. Any suggestions?

<?php
 if (is_single()){
  include(STYLESHEETPATH.'/sidebar-single.php');}
 elseif (is_page()){
  include(STYLESHEETPATH.'/sidebar-index.php');}
 elseif (is_category('fame-game')){
  include(STYLESHEETPATH.'/sidebar-fame-game.php');}
 elseif (bp_is_user_profile()){
  include(STYLESHEETPATH.'/sidebar-act.php');}
 else {
  include(STYLESHEETPATH.'/sidebar-index.php');}
?>

Link to buddypress conditional statements codex http://codex.buddypress.org/developer-docs/conditional-template-tags/

SOLVED! See answer with comments below given by Boone Gorges. Here is the resolved code.

<?php
 if (is_single()){
 include(STYLESHEETPATH.'/sidebar-single.php');}
 elseif (is_page() && !bp_is_profile_component()){
 include(STYLESHEETPATH.'/sidebar-index.php');}
 elseif (is_category('fame-game')){
 include(STYLESHEETPATH.'/sidebar-fame-game.php');}
 elseif (bp_is_profile_component()) {
 include(STYLESHEETPATH.'/sidebar-act.php');}
 else {
 include(STYLESHEETPATH.'/sidebar-index.php');}
?>
share|improve this question

closed as off-topic by toscho Aug 4 at 21:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
When and where're you adding this code? –  kaiser Mar 13 '12 at 14:03
    
Oh sorry this is the code in my sidebar.php. –  Pollux Khafra Mar 13 '12 at 14:21

2 Answers 2

up vote 2 down vote accepted

Your problem may be the choice of bp_is_user_profile(). This only returns true when you are literally looking at the xprofile component - the 'Profile' tab of a user's page. bp_is_user() is more general, returning true whenever you're viewing a user page (even if it's user activity, user groups, etc).

[EDIT]

After further discussion with the OP, it looks as if the culprit is is_page(). Since BP 1.5, BuddyPress uses WP Pages to display content. That means that the is_page() case was returning true. To exclude BP content from this condition, amend your check as follows:

is_page() && !bp_is_blog_page()

Alternatively, if you want the is_page() content to show on BP content too, except for user pages,

is_page() && !bp_is_user()

or, to limit it to the profile,

is_page() && !bp_is_profile_component()

share|improve this answer
    
I changed it to bp_is_user() and it still returns the last default option for the sidebar. –  Pollux Khafra Mar 13 '12 at 15:56
    
What's the URL for the page you're testing? Does it look like this: http://example.com/members/boonebgorges/? –  Boone Gorges Mar 13 '12 at 16:36
    
I was using define ( 'BP_ENABLE_ROOT_PROFILES', true ); to have top level profiles. I changed it back to check but still no dice. So yes it still doesnt work with that permalink structure. –  Pollux Khafra Mar 13 '12 at 16:49
    
Strange. You could try bp_displayed_user_id() (which will return an int on a user page and 0 otherwise), but I doubt that will work either, since bp_is_user() is more or less a wrapper for bp_displayed_user_id(). I don't quite understand how user content could be displaying on the rest of the page if these functions return false/0. Are you working with a custom theme, or a child theme of bp-default, or what? Are you loading sidebar.php in a non-standard way? –  Boone Gorges Mar 13 '12 at 20:18
    
Im using a child theme of bp-default. I use get_sidebar() to call the sidebar on template pages. I don't get it =( –  Pollux Khafra Mar 13 '12 at 20:55

Read the comments

...for further explanation also read about locate_template().

<?php
// Build $sidebars array in order of PRIORITY. First things first » overrides later
if ( is_single() )
{
    $sidebars[] = 'single';
}
// Not needed as it's the default one
// elseif ( is_page() )
// {
//     $sidebars[] = 'index';
// }
elseif ( is_category('fame-game') )
{
    $sidebars[] = 'fame-game';
}
elseif ( bp_is_user_profile() )
{
    $sidebars[] = 'act';
}
$sidebars[] = 'index';

// Build names:
foreach ( $sidebars as $index => $name )
    $sidebars[ $index ] = "sidebar-{$name}.php";

// Load & require_once the sidebar
locate_template( $sidebars, true );
?>
share|improve this answer

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