Re: Buddypress custom theme with alternate sidebars for different pages
Here is my Sidebar which does exactly what you want: Show different sidebars on different BP sections of the site.. It does not work 100% (blog sidebar does not show up yet) but it should get you started. You use BP conditional tags to show/hide the different sidebars depending where the user is on the site:
<?php do_action( 'bp_before_sidebar' ) ?>
<div id="sidebar">
<div class="padder2">
<?php
locate_template( array( 'accordeon.php' ), true );
?>
<?php do_action( 'bp_inside_before_sidebar' ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php do_action( 'bp_before_sidebar_me' ) ?>
<?php endif; ?>
<?php /* Show forum tags on the forums directory */
if ( BP_FORUMS_SLUG == bp_current_component() && bp_is_directory() ) : ?>
<div id="forum-directory-tags" class="widget tags">
<h3 class="widgettitle"><?php _e( 'Forum Topic Tags', 'buddypress' ) ?></h3>
<?php if ( function_exists('bp_forums_tag_heat_map') ) : ?>
<div id="tag-text"><?php bp_forums_tag_heat_map(); ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="padder3">
<?php if(bp_is_group()){
if(!dynamic_sidebar("Group Sidebar")){?>
<?php }
}
else if(bp_is_member()){
if(!dynamic_sidebar("Profile Sidebar")){ //if user profile etc
?>
<?php
}
}
else if(bp_is_blog_page() || bp_is_directory()){
if(!dynamic_sidebar("Blog Sidebar")){?>
<?php } }
else dynamic_sidebar( 'Sidebar' )?>
<?php dynamic_sidebar( 'sidebar' ) ?>
</div>
<?php do_action( 'bp_inside_after_sidebar' ) ?>
<?php /* Show forum tags on the forums directory */
if ( BP_FORUMS_SLUG == bp_current_component() && bp_is_directory() ) : ?>
<div id="forum-directory-tags" class="widget tags">
<h3 class="widgettitle"><?php _e( 'Forum Topic Tags', 'buddypress' ) ?></h3>
<?php if ( function_exists('bp_forums_tag_heat_map') ) : ?>
<div id="tag-text"><?php bp_forums_tag_heat_map(); ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
</div><!-- .padder -->
</div><!-- #sidebar -->
<?php do_action( 'bp_after_sidebar' ) ?>
Make sure to register the sidebars in your functions.php (of your child theme)
if (function_exists('register_sidebar')) {
register_sidebar(
array(
'name' => 'Blog Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => 'Profile Sidesbar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => 'Group Sidebar ',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => 'Left Footer',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => 'Middle Footer',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => 'Right Footer',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
)
);
}