WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple Sidebars Stopped Working (7 posts)

  1. Tchaaa
    Member
    Posted 1 year ago #

    A client I'm making a website for has requested multiple widgetised sidebars, ie, one for each page.

    I made a page template for each page, and registered a widget space for each page, and hooked up the relevant widget space in the template's file.

    I tested it, and it worked, I popped downstairs to make some dinner and upon coming back having changed nothing at all it's not worked.

    In functions.php

    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'Press Page','id' => 'press','description' => "Shown on pages with the Press Page Template", 'before_widget' => '<div id="%1$s" class="widget %2$s">','after_widget' => '</div>','before_title' => '<h3>','after_title' => '</h3>'
    ));

    In the template

    <?php get_sidebar('press'); ?>

    Literally can't understand what's happened as it was working and I hadn't touched anything! Urgently need help too as said client is getting rather tetchy about her website not being done right this second! A problem which I'm sure many of you have to put up with, just like myself.

  2. Tchaaa
    Member
    Posted 1 year ago #

    Turns out I have done something.

    It works if I have just one widget group registered in the functions file, however if I add more than one it stops everything.

    Odd considering there are other widget's already defined in this theme. Now starting to really head scratch.

  3. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    no need for a check if register_sidebar exists anymore... they have been around for years....

    Wrap up your sidebar registrations and latch on to widgets_init

    function voodoo_widgets_init() {
    	register_sidebar( array(
    		'name' => __( 'Advertising Sidebar', 'twentytwelve' ),
    		'id' => 'voodoo-ad-widget-area',
    		'description' => __( 'Horizontal Ad Widget', 'twentytwelve' ),
    		'before_widget' => '<aside id="%1$s" class="top-widget %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    }
    /** Register sidebars by running sidebars on the widgets_init hook. */
    add_action( 'widgets_init', 'voodoo_widgets_init' );

    You can just keep copy and altering the

    register_sidebar( array(
    		'name' => __( 'Advertising Sidebar', 'twentytwelve' ),
    		'id' => 'voodoo-ad-widget-area',
    		'description' => __( 'Horizontal Ad Widget', 'twentytwelve' ),
    		'before_widget' => '<aside id="%1$s" class="top-widget %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );

    Portion for more sidebars (before that closing } curly brace)

  4. Tchaaa
    Member
    Posted 1 year ago #

    Just tried what you advised and it brought the entire site down until I put it back to how it was.

    I think I'm getting closer. Everything should in theory work.

    It turns out I can register as many sidebars as I like and not encounter problems. It's when I call them with get_sidebar('idhere') that it starts to mess up.

    If I call the 'about' ID on both the press and about pages, works fine. If I use both 'about' and 'press' on the same page in different get_sidebar tags, it works fine. However if I put
    get_sidebar('about') on the about page, and get_sidebar('press') on the press page, both go back to the default sidebar.

    I think I'm a bit out of my depth.

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    **HEADDESK**

    get sidebar is looking for a file, or it defaults to sidebar.php

    Are you making files for each sidebar?

    http://codex.wordpress.org/Function_Reference/get_sidebar

    if you don't wish to make files for each you need:
    http://codex.wordpress.org/Function_Reference/dynamic_sidebar

    you would also need that dynamic_sidebar IN the sidebar file if going that route

    dynamic_sidebar hooks up the widget area, get_sidebar calls the sidebar file

    You can get context looking at various themes... for instance from 2012

    <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    		<div id="secondary" class="widget-area" role="complementary">
    			<?php dynamic_sidebar( 'sidebar-1' ); ?>
    		</div><!-- #secondary -->
    	<?php endif; ?>
  6. Tchaaa
    Member
    Posted 1 year ago #

    Well I feel stupid, through a lack of caffeine and sleep, I made the rookie mistake of not making sure I'd actually saved the sidebar file I'd created.

    Thank you though, I'd be sitting here for hours trying to figure what I'd done if it weren't for your help!

  7. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    Ah! Well, I'm glad we got your memory jarred!

Topic Closed

This topic has been closed to new replies.

About this Topic