WordPress.org

Support

Support » Themes and Templates » Calling different sidebars code

Calling different sidebars code

  • Hi

    I know this topic has been raised before but having searched through, I’m still struggling.

    I’ve created 2 new sidebar configurations (called sidebarblog and sidebarindex) which, you may guess, display different sidebars depending on it being a blog page or a mainpage

    I’ve tested the code within each and know it to work.

    The sidebar.php now contains the following :

    <?php if (is_home()) {
    get_sidebarblog();
    } else {
    get_sidebarindex();
    }
    ?>

    I get an error that I don’t understand : Fatal error: Unknown function: get_sidebarindex() in …sidebar.php on line 4

    The url is http://imjon.com

    That suggests to me that the files it’s looking for don’t exist, but they do. I’m sure there’s something very simple I’m doing wrong here, but I can’t see it. If you can help, I’d be grateful.

    Jonathan

Viewing 3 replies - 1 through 3 (of 3 total)
  • Wouldn’t you still need to define it from the theme’s page.php or single.php (or wherever you’re wanting it) – something like:
    <?php include (TEMPLATEPATH . "/sidebarindex.php"); ?>

    Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

    The “get_sidebar()” is a function, not a file. It’s a convenience built into WordPress for a number of reasons.

    However, you can’t just make them up on the fly like that. If you do, then you need to use code like samboll gave above to include the files directly.

    solved the problem using (for sidebar.php)

    <?php if (is_home()) {
    include (TEMPLATEPATH . “/sidebarblog.php”);

    } else {
    include (TEMPLATEPATH . “/sidebarother.php”);
    }
    ?>

    The code for each of the other sidebars are variations on the original… thanks for your help. Hope this code helps others.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Calling different sidebars code’ is closed to new replies.