WordPress.org

Ready to get started?Download WordPress

Forums

2 different sidebars (7 posts)

  1. hopeworks
    Member
    Posted 6 years ago #

    I am using the blixed theme.

    I have a static front page.

    I would like to have a different sidebar for the posts page then the static front page. Using widgets on both.

    Any help? Thanks.
    youpickthesermon.com

  2. davidemorgan
    Member
    Posted 6 years ago #

    In functions.php, if you're already widgetized you'll find this (if not add it):

    if ( function_exists('register_sidebar') )
    register_sidebar();

    To do multiple sidebars you'll need this, too:

    if ( function_exists('register_sidebars') )
    register_sidebars(2);

    The (2) represents your 2 sidebars. If you want 3, put in 3, and so on.

    Now in your sidebar.php, we're going to mess with the code a bit. Where you currently find:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

    Replace with this:

    <?php if (is_home()) {
    if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else :
    } else {
    if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : } ?>
    //Put in stuff that'd show in case of no widgets
    <?php endif; ?>

    I'm sure there's a cleaner way to do it, but...

    • dynamic_sidebar(1) will show on your home page and
    • dynamic_sidebar(2) will show on every other page

    At least it should. Haven't tried it. Hope it works.

  3. davidemorgan
    Member
    Posted 6 years ago #

    Parse errors. Never mind me.

  4. davidemorgan
    Member
    Posted 6 years ago #

    Okay, do what I said in functions.php, but in your sidebar.php, but this instead:

    <?php if ( function_exists('dynamic_sidebar')):
    if (is_home()) dynamic_sidebar(1);
    else dynamic_sidebar(2);
    endif; ?>
  5. hopeworks
    Member
    Posted 6 years ago #

    I get two sidebars in widgets panel but no sidebars show up on site.

    here is the code (w/o your changes)

    <?php
    if ( function_exists('register_sidebar') )
    {
    register_sidebar(array('before_widget' => '',
    		'after_widget' => '',
    		'before_title' => '<h2><em>',
    		'after_title' => '</em></h2>',
    		));
    }

    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else : ?>

  6. epulula
    Member
    Posted 6 years ago #

    Could someone explain me what is the meaning of this statement:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(1) ) : ?>

  7. palamedes
    Member
    Posted 6 years ago #

    That is a simple line of PHP which says this;

    IF the function "dydnamic_sidebar" doesn't exist or running the function dynamic_sidebar(1) didn't output anything then execute the following code until "else" or "endif"

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags