WordPress.org

Ready to get started?Download WordPress

Forums

alternate sidebar not showing (2 posts)

  1. lbrocka
    Member
    Posted 5 years ago #

    I'm usually pretty successful in figuring these things out, but this one has me stumped. I think the problem may be in the functions.php. I have added 2 additional page templates(pagekids and pageteen) and 2 additional sidebars (sidebarkids/sidebarteen)
    Both sidebars appear on the widgets admin and I have placed different widgets on each of the sidebars, but only the original default sidebar shows on all pages. The correct templates are applied to the specific pages and I have changed the "get_sidebar" code in each of the special page templates to php include (TEMPLATEPATH . '/sidebarteen.php') etc. Function.php code:
    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar1',
    'before_widget' => '<div class="sideblock">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
    ));

    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebarkids',
    'before_widget' => '<div class="sideblock">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
    ));

    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebarteen',
    'before_widget' => '<div class="sideblock">',
    'after_widget' => '</div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
    ));
    `
    the site is under construction at http://adelpl.org/blog
    Thanks!!

  2. martyz
    Member
    Posted 5 years ago #

    If you're looking to have a different sidebar for different pages, you'll need the page ID for this code that works for me, as well as different sidebars named sb-1.php, sb-2.php, etc. as well as your sidebar.php file.

    In your 'page template' you can replace <?php get_sidebar(); ?> with the code below:

    <?php 
    
    if  (is_page('3'))  { 
    
    include(TEMPLATEPATH . '/sb-1.php'); 
    
    } elseif (is_page('5')) { 
    
    include(TEMPLATEPATH . '/sb-2.php');
    
    } elseif (is_page('25')) { 
    
    include(TEMPLATEPATH . '/sb-3.php');
    
    } elseif (is_page('29')) { 
    
    include(TEMPLATEPATH . '/sb-4.php');
    
    } elseif (is_page('7')) { 
    
    include(TEMPLATEPATH . '/sb-5.php');
    
    } else { 
    
    get_sidebar();
    
    }	
    
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic