Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress custom theme with alternate sidebars for different pages

  • @frenchtowner

    Participant

    I am continuing to work on my custom theme based on the BuddyPress Default 1.2.2.1 theme and I have been able to add customized widget page templates for the homepage based on Sarah Gooding’s tutorial on WPMU.org:

    http://wpmu.org/how-to-widgetize-a-page-post-header-or-any-other-template-in-wordpress/

    I assumed that since that worked like a charm that I could get an alternate sidebar working on certain pages, but I just can’t get it to work. No matter what I do with any custom page template, the default sidebar is always shown. What am I doing wrong?

    What php code should I use to call the alternate sidebar?

    Do I have to create a whole new [second version] of sidebar.php as in sidebar2.php or custom-sidebar.php?

    Here is one version of my custom-page template with the working top and bottom widget areas and the alternate sidebar that is displaying the default sidebar:

    <?php
    /*
    Template Name: Custom 2
    */
    ?>

    <?php get_header() ?>

    <div id="content">
    <div class="padder">

    <?php do_action( 'bp_before_blog_home' ) ?>

    <div class="page" id="blog-latest">

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("widgetized-page-top-2") ) : ?>
    <?php endif; ?>
    <?php if ( have_posts() ) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <?php do_action( 'bp_before_blog_post' ) ?>

    <div class="post" id="post-<?php the_ID(); ?>">
    <div class="author-box">
    <?php echo get_avatar( get_the_author_meta( 'user_email' ), '50' ); ?>
    <p><?php printf( __( 'by %s', 'buddypress' ), bp_core_get_userlink( $post->post_author ) ) ?></p>
    </div>
    <div class="post-content">
    <h2 class="posttitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( 'Permanent Link to', 'buddypress' ) ?> <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

    <div class="entry">
    <?php the_content( __( 'Read the rest of this entry &rarr;', 'buddypress' ) ); ?>
    </div>

    <p class="postmetadata"><span class="tags"><?php the_tags( __( 'Tags: ', 'buddypress' ), ', ', '<br />'); ?></span> <span class="comments"><?php comments_popup_link( __( 'No Comments »', 'buddypress' ), __( '1 Comment »', 'buddypress' ), __( '% Comments »', 'buddypress' ) ); ?></span></p>
    </div>

    </div>

    <?php do_action( 'bp_after_blog_post' ) ?>

    <?php endwhile; ?>

    <div class="navigation">

    <div class="alignleft"><?php next_posts_link( __( '&larr; Previous Entries', 'buddypress' ) ) ?></div>
    <div class="alignright"><?php previous_posts_link( __( 'Next Entries &rarr;', 'buddypress' ) ) ?></div>

    </div>

    <?php else : ?>

    <h2 class="center"><?php _e( 'Not Found', 'buddypress' ) ?></h2>
    <p class="center"><?php _e( 'Sorry, but you are looking for something that isn\'t here.', 'buddypress' ) ?></p>

    <?php locate_template( array( 'searchform.php' ), true ) ?>

    <?php endif; ?>
    </div>

    <?php do_action( 'bp_after_blog_home' ) ?>
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("widgetized-page-bottom-2") ) : ?>
    <?php endif; ?>

    </div><!-- .padder -->
    </div><!-- #content -->

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("custom-sidebar") ) : ?>
    <?php endif; ?>

    <?php get_footer() ?>

    I’m not trying to take the easy way out here guys. I have been struggling with this and researching and trying different strategies for 2 days now. I would appreciate any guidance any of you could offer.

    Sincerely grateful,

    John Stringfellow

Viewing 4 replies - 1 through 4 (of 4 total)
  • @r-a-y

    Keymaster

    I’d rather use a widget conditional plugin like Widget Context or Widget Logic for the sidebar.

    Widget Context is best for non-coders.

    @andrea_r

    Participant

    Did you create a new page and apply that page template to it?

    Though I woudl really go the route of using the widget logic plugin.

    @bowromir

    Participant

    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>',
    )
    );
    }

    @frenchtowner

    Participant

    First of all, I want to thank you all for your help. Sometimes I feel like I am writing to myself when I ask questions here. I am very grateful to have gotten so many responses and such good help!

    r-a-y,

    I will check into that option. I had used widget logic and one point for another issue, but I never thought about it in this context.

    Andrea_r,

    I did make a new page and apply that template. That’s why I don’t understand it not working!

    Bowe,

    I will try your option and see if I can get it working. Does your blog sidebar not show at all? And if it doesn’t show, what is showing in that space, no sidebar and just a wider content section?

    John

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Buddypress custom theme with alternate sidebars for different pages’ is closed to new replies.
Skip to toolbar