WordPress.org

Ready to get started?Download WordPress

Forums

Merging two columns into one (7 posts)

  1. eagleout
    Member
    Posted 4 years ago #

    Is there a way, either through editing a theme or through a widget, to create a single column sidebar underneath a two column sidebar?

    Thanks for your help

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    It can be done by editing the theme. You can have multiple sidebars using calls like get_sidebar('one') and get_sidebar('two') etc.

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

  3. eagleout
    Member
    Posted 4 years ago #

    Would it be something like this for the single sidebar under the double?

    <?php get_sidebar('left'); ?>
    <?php get_sidebar('right'); ?>
    <?php get_sidebar('center'); ?>

  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Yes but then you'd need to create a sidebar-center.php template file with all of the markup for that single column plus add styling via CSS.

  5. eagleout
    Member
    Posted 4 years ago #

    Well, I got the third sidebar to display the way I want on the index page per your suggestions. Created a new sidebarCenter.php file, edited functions.php and style.css with the relevant info so it would show up on widgets and it works fine.

    Only problem now is getting it to show up when viewing posts. I tried adding <?php include (TEMPLATEPATH . '/sidebarCenter.php'); ?> to the single and post files but the sidebar ends up in the post area instead of the sidebar. I don't think the additional sidebar is being registered properly and am kinda lost when reading over the docs about that.

    Any suggestions?

  6. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Rename the new sidebar file to sidebar-center.php and then use <?php get_sidebar('center'); ?> immediately above (or below) the call to your existing sidebar.

    In terms of registering the new sidebar, have a look what is being used for your existing sidebar in functions.php and base your new register_sidebar() on that. Mine tend to go something like:

    FUNCTIONS.PHP

    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name'=> 'Main Sidebar',
    		'id' => 'main_sidebar',
    		'before_widget' => '<li id="%1$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    	register_sidebar(array(
    		'name'=> 'Center Sidebar',
    		'id' => 'center_sidebar',
    		'before_widget' => '<li id="%1$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    }

    SIDEBAR.PHP

    <div class="sidebar" id="main_sidebar">
    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Main Sidebar')) : ?>
    [ hardcoded stuff ]
    <?php endif; ?>
    </div>

    SIDEBAR-CENTER.PHP

    <div class="sidebar" id="center_sidebar">
    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Center Sidebar')) : ?>
    [ hardcoded stuff ]
    <?php endif; ?>
    </div>

    Giving each sidebar its own unique id means that you can then apply specialised CSS as needed whilst still styling generic stuff using the .sidebar class.

    Hope that helps

  7. aradams
    Member
    Posted 4 years ago #

    @esmi,

    Thanks so much for your instructions. I've been struggling with multiple widgetized sidebars and none of the tuts I found worked. Yours did!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags