WordPress.org

Ready to get started?Download WordPress

Forums

2 sidebars, how do i? (14 posts)

  1. bschwarting
    Member
    Posted 6 years ago #

    I have a theme that lists sub pages on the sidebar if they are available. I only want sub pages on some of my pages, so here is what I did to try and fix it. I created a template called "no sub pages" that pulled a sidebar2 instead of the original sidebar. When I do this, i get the following error:

    Fatal error: Call to a member function on a non-object in /homepages/1/d248900016/htdocs/wp-content/themes/mushblue-10/sidebar2.php on line 20

    I have added this in functions.php:

    <?php

    function sidebar1(){
    include (TEMPLATEPATH . "/sidebar.php");
    }

    function sidebar2(){
    include (TEMPLATEPATH . "/sidebar2.php");
    }

    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar1',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    register_sidebar(array('name'=>'sidebar2',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    ?>

    Ideas as to where I go next? What am i missing?

    I call the 2nd sidebar like this, <?php sidebar2(); ?>

    Also, here is the code on the 1st sidebar that pulls the subpages:

  2. <h3 class="sidebartitle"><?php echo $parent_title; ?> <?php _e('Subpages'); ?></h3>
    <ul class="list-page">
    <?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?>

  3. I just removed that code in sidebar2.

  • kohaku
    Member
    Posted 6 years ago #

    I'm using two sidebars on a test site. I'll show you my code and hope that helps you.

    Function.php

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    register_sidebar(array('name'=>'below',
    'before_widget' => '<div class="block2">',
    'after_widget' => '</div>',
    'before_title' => '',
    'after_title' => '',
    ));
    ?>

    My main sidebar is named sidebar and I have it called on sidebar.php.

    sidebar.php

    <div id="sidebar">
    <ul id="sidelist">

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

    <!-- end sidelist -->
    </div><!-- end sidebar -->

    My second sidebar is loaded into my footer.php, but you could work it into a side-by-side if you want.

    footer.php

    <div id="info">

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

    </div> <!-- end info -->

    I hope that helps!

  • bschwarting
    Member
    Posted 6 years ago #

    thanks for that.

    am i pulling the sidebar correctly in my template by using this?

    <?php sidebar2(); ?>

  • kohaku
    Member
    Posted 6 years ago #

    If you are using dynamic sidebars, that really isn't the best way.

    I'm not fantastic with php, but I don't think that code is properly pulling what it needs to.

  • bschwarting
    Member
    Posted 6 years ago #

    also, here is line #20 where the error is:

    if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_type != 'attachment'")) {

  • bschwarting
    Member
    Posted 6 years ago #

    ok, i just used what was already in my page.php and mirrored that.

  • kohaku
    Member
    Posted 6 years ago #

    A lot of it might have something to do with what theme you are using.

    If you copied it, then I'm not exactly sure why it isn't working.

    I'm not too familiar with the code from line 20.

    What theme are you using? I'd like to take a look.

  • bschwarting
    Member
    Posted 6 years ago #

  • kohaku
    Member
    Posted 6 years ago #

    Do you want the sidebars right next to each other?

    If so, you might try another theme that already had three columns to make the editing easier.

  • bschwarting
    Member
    Posted 6 years ago #

    no, i don't want them next to each other.

    on one page i want sidebar1 to be pulled.

    on another page i want sidebar2 to be pulled.

  • kohaku
    Member
    Posted 6 years ago #

    For example:

    The home page shows sidebar1 and any other page shows sidebar2.

    Is that right?

  • kohaku
    Member
    Posted 6 years ago #

    You might try:

    <?php if (is_home()) {
    include (TEMPLATEPATH . "/sidebar1.php");
    
    } else {
    include (TEMPLATEPATH . "/sidebar2.php");
    }
    ?>
  • bschwarting
    Member
    Posted 6 years ago #

    the only pages that will show sidebar2 is the ones that have the "no sub pages" template assigned to them.

  • kohaku
    Member
    Posted 6 years ago #

    I don't know how to apply conditional tags to pages with certain templates.

    The above fix is the only one that I know of that might help you.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags