WordPress.org

Ready to get started?Download WordPress

Forums

How to use multiple sidebars - getting them in different page tmeplates (11 posts)

  1. Mere1dcrr
    Member
    Posted 2 years ago #

    Ok, I'm at a loss here. I've tried just about everything I can think of...

    I am trying to create different sidebars and insert them in different page templates so that there is a different sidebar for a specific page. I have created page-2.php, page-3.php, and page-4.php, have uploaded them into my themes folder, and have named them properly so that they show up under the 'templates' dropdown menu under the 'edit page' page. So I believe the page templates are good. I also have created sidebar-2.php, sidebar-3.php, and sidebar-4.php, have uploaded them into my themes folder, and they show up under 'templates' under the 'edit themes' page. So I think the sidebars are ok. The problem I am having is getting the correct html coding in the functions.php file. I have copy and pasted multiple versions of html that says it will create multiple sidebars, but it never works. I'm not quite sure exactly where in the html to out it either. Here is the current html for the sidebar section in my functions.php file:

    <?php if ( ! isset( $content_width ) )
    $content_width = 603;
    function naturefox_sidebar() {
    register_sidebar(array(
    		'name' => __( 'Sidebar Widget Area', 'naturefox' ),
    		'id' => 'sidebar-widget-area',
    		'description' => __( 'The sidebar widget area', 'naturefox' ),
    		'before_widget' => '<li>',
    		'after_widget' => '</li>',
    		'before_title' => '<h2>',
    		'after_title' => '</h2>',
    	));
    }
    add_action('widgets_init', 'naturefox_sidebar');

    [Please post code or markup snippets between backticks or use the code button.]

    Help! Thanks!

  2. vtxyzzy
    Member
    Posted 2 years ago #

  3. vtxyzzy
    Member
    Posted 2 years ago #

    If you can edit your first post, please correct the code by enclosing in backticsk. An unmatched backtick is messing up the display.

  4. Mere1dcrr
    Member
    Posted 2 years ago #

    <?php
    if ( ! isset( $content_width ) )
    $content_width = 603;
    
    function naturefox_sidebar() {
    register_sidebar(array(
    		'name' => __( 'Sidebar Widget Area', 'naturefox' ),
    		'id' => 'sidebar-widget-area',
    		'description' => __( 'The sidebar widget area', 'naturefox' ),
    		'before_widget' => '<li>',
    		'after_widget' => '</li>',
    		'before_title' => '<h2>',
    		'after_title' => '</h2>',
    	));
    }
    
    add_action('widgets_init', 'naturefox_sidebar');
  5. vtxyzzy
    Member
    Posted 2 years ago #

    Did you check the article I referenced?

  6. Mere1dcrr
    Member
    Posted 2 years ago #

    I had visited that site before, copy and pasted the big long html, but got me no where

  7. dragonsjaw
    Member
    Posted 2 years ago #

    This is what I have for one of my custom sidebars in functions, doesn't look that different from yours but does work:

    add_action( 'widgets_init', 'my_register_sidebars' );
    
    function my_register_sidebars() {
    	//Register the 'custom' sidebar, located at the top of the sidebar
    	register_sidebar( array(
    			'name' => __( 'Custom Sidebar' ),
    			'id' => 'custom',
    			'description' => __( 'Custom Sidebar for bcindex' ),
    			'before_widget' => '<div id="%1$s" class="widget %2$s">',
    			'after_widget' => '</div>',
    			'before_title' => '<h3 class="widget-title">',
    			'after_title' => '</h3>'
    		)
    	);
  8. vtxyzzy
    Member
    Posted 2 years ago #

    I don't know how to explain it any clearer than that article. The code there was not meant to be copied/pasted, but to be altered to use your own sidebar names.

  9. photographypool1
    Member
    Posted 2 years ago #

    once you have the multiple sidebars being called correctly. How can we use most widgets except for the one that contains a banner affiliate link and replace that with another? Can we insert the html inbetween the code located in the sidebar.php files for it to show, or just get rid of the section that says

    if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>

    so the primary widget area is always active?

  10. sicktb
    Member
    Posted 2 years ago #

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebarname1',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h4>',
    'after_title' => '</h4>',
    ));
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebarname2',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h4>',
    'after_title' => '</h4>',
    ));
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebarname3',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h4>',
    'after_title' => '</h4>',
    ));
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebarname4',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h4>',
    'after_title' => '</h4>',
    ));
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebarname5',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h4>',
    'after_title' => '</h4>',
    ));

    ?>

    Here this works for me; 5 sidebars. Rember this is just the functions.php
    You also need to make te code on the html page where you whant the sidebars.

    If you whant to remove a sidebar just deleet the peace i marked bold from functions.php

    This code must be on the html page

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

    etc

  11. photographypool1
    Member
    Posted 2 years ago #

    Thanks for the response. While waiting for a reply, I came across this great widget by the name of 'Widget Locationizer' available through the wordpress plug in section. It allows users to customise which of their widgets they're like to show on each page. I found this to be the most user friendly and time efficient way of achieving the same result.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags