Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress 2 – Creating a new sidebar area for your theme

  • @alieninformer

    Member

    I figured since I was asking for help on something here:

    http://bbpress.org/forums/topic/function-calls

    I would at least give a little something that I believe some people may find useful. I may not explain this well so please feel free to ask questions and I’ll do my best to help you.

    I needed to create a whole new sidebar for my forum page and after some research and using the old noggin I came up with the following. Please note that this should be a good common usage for most themes but your situation may be unique. Adjust as needed.

    First, open your functions.php file and copy the following in there:

    // Forum Sidebar Widget Area. Empty by default.
    register_sidebar( array(
    'name' => __( 'Forum Widget Area', 'twentyten' ),
    'id' => 'forum-widget-area',
    'description' => __( 'The Forum Widget Area', 'twentyten' ),
    'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    'after_widget' => '',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
    ) );

    Again, each case may be different but generally this will work. What this will do is create a new Widgetized sidebar area (located under Appearances >> Widgets)

    Alternatively, You can copy your existing widget code in functions.php for widgets but be sure to rename the areas, especially id, as I have above (forum-widget-area was originally sidebar-widget-area).

    Take note, as well of the class= and id= I have. Those are useful for my blog but you may be using different tags for yours. Adjust as needed.


    Then Create a new file and name it anything you want, for our testing purposes we’re going to use forum-sidebar.php

    Copy and paste your code from sidebar.php into your new forum-sidebar.php file.

    My original looks like this:

    // A Sidebar for widgets
    if ( is_active_sidebar( 'sidebar-widget-area' ) ) : ?>

    <div id="sidebar" class="widget-area" role="complementary">
    <ul class="xoxo">
    <?php dynamic_sidebar( 'sidebar-widget-area' ); ?>

    </div>

    As you can see, I have two spaces calling the sidebar-widget-area that was previously declared in functions.php. Yours should be very similar to this or at least easy enough to figure out.

    What you need to do is rename the two fields within the () areas to what you declared when setting up your code in functions.php, mine is

    // A Sidebar for widgets
    if ( is_active_sidebar( 'forum-widget-area' ) ) : ?>

    <div id="sidebar" class="widget-area" role="complementary">
    <ul class="xoxo">
    <?php dynamic_sidebar( 'forum-widget-area' ); ?>

    </div>

    Notice how I changed sidebar-widget-area to forum-widget-area ?

    We do this so that when your forum page is called, it shows the widgets you’ll setup later.


    Now, Open your Page Template and find:

    <?php get_sidebar(); ?>

    Or something similar. generally this is at the bottom of the code.

    Replace that with:

    <?php
    $uri = $_SERVER['REQUEST_URI'];
    if ( strpos($uri,'YOUR-FORUM-BASE') !== false ) {

    include(TEMPLATEPATH . '/forum-sidebar.php');

    } else {

    get_sidebar();

    }
    ?>

    “forum-sidebar.php” is the file you created earlier and YOUR-FORUM-BASE is the “Forums base” you have defined for your forums settings (in Settings >> Forums). Also please note the / before the file name. With this code you’ll need it.

    What this does is calls your primary URL http://yoursite.com and then attempts to detect if it’s on THIS URL or ANOTHER.

    So if yoursite.com/YOUR-FORUM-BASE then SHOW THIS else SHOW THAT.

    Using this code you can have an entirely seperate widget area for your forum page so you can make better use of the bbPress widgets without overdoing it with your current sidebar setup.

    Someone may have a better or more elegant way of achieving this but this has worked for me and it works well. I hope anyone finds it useful.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @gautamgupta

    Participant

    Thanks for the share! You might want to use is_bbpress() function (found in bbp-includes/bbp-common-template.php instead of $uri = $_SERVER['REQUEST_URI']; if ( strpos($uri,'YOUR-FORUM-BASE') !== false ) {

    I have wrapped your code blocks in backticks for easier reading. :)

    @alieninformer

    Member

    Awesome! Thanks and I’ll remember that next time I have something to share.

    And I honestly don’t know enough about bbPress (yet) to integrate that yet BUT I will soon I hope lol.

    I also wanted to point out the reason I have (‘sidebar-widget-area’) in mine is I also have footer widgets. By default, then most are simple () and all you need to do is add ‘widget name’ here.

    @tryingtoregister

    Member

    @alieninformer, thanks for sharing!

    You can also call an alternate sidebar in bbPress just as you can in your base WP install, so <?php get_sidebar('alternateside'); ?> would call sidebar-alternateside.php and that file can be kept in the WP theme folder so that it could be shared with other non-bbPress pages.

    @alieninformer

    Member

    Thanks David! The truth is I still have some trouble copying my bbpress child theme into WordPress. Every time I do I keep getting errors but it’s only a matter of time before I get it down.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar