WordPress.org

Ready to get started?Download WordPress

Forums

Calling different sidebars code (4 posts)

  1. jonthegeologistgmailcom
    Member
    Posted 7 years ago #

    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

  2. Samuel B
    moderator
    Posted 7 years ago #

    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"); ?>

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    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.

  4. jonthegeologistgmailcom
    Member
    Posted 7 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic