WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to Create new Widget Area (5 posts)

  1. ktsixit
    Member
    Posted 4 years ago #

    Hi all,
    I'm new to wordpress and it's difficult for me to find some basic information in forums and documentation.

    I'm trying to create my own widget areas, and place my widgets there in administration panel. But I cannot find some instructions of how to do that.

    For now, there is only one widget area in the template I'm using as a base called "Sidebar 1". I'd like to add more areas like this one. Can you give me some guidelines or post some useful links please?

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

    http://codex.wordpress.org/Widgetizing_Themes

    You can use this approach to widgetize any template.

  3. ktsixit
    Member
    Posted 4 years ago #

    The template I'm using has already done what this page says. The only useful thing for me is the last section:

    I have a theme with more than one sidebar. How do I make them all dynamic?

    Oh, that’s easy. Instead of register_sidebar() you should use register_sidebars(n) where n is the number of sidebars. Then place the appropriate number in the dynamic_sidebar() function, starting with 1. (There are several other ways to use these function. See the API).

    You can even give your sidebars names rather than numbers, which lets you maintain a different set of saved sidebars for each theme. But if you need to know so much about the plugin, why aren’t you reading the API?

    But this is too general and I don't understand exactly what kind of code I should add in functions.php file. The register_sidebar function is like this one:

    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h5 class="widgettitle">',
            'after_title' => '</h5>',
        ));
  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    Examples of multiple widget-capable areas:

    FUNCTIONS.PHP

    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name'=> 'Top Tabs',
    		'id' => 'top_tabs',
    		'before_widget' => '<li id="%1$s" class="widget %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h2 class="offscreen">',
    		'after_title' => '</h2>',
    	));
    	register_sidebar(array(
    		'name'=> 'Top Sidebar',
    		'id' => 'top_sidebar',
    		'before_widget' => '<li id="%1$s" class="widget %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    	register_sidebar(array(
    		'name'=> 'Left Sidebar',
    		'id' => 'left_sidebar',
    		'before_widget' => '<li id="%1$s" class="widget %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    	register_sidebar(array(
    		'name'=> 'Right Sidebar',
    		'id' => 'right_sidebar',
    		'before_widget' => '<li id="%1$s" class="widget %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    }

    RIGHT SIDEBAR:

    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Right Sidebar')) : ?>
    [ do default stuff if no widgets ]
    <?php endif; ?>

    LEFT SIDEBAR

    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Left Sidebar')) : ?>
    [ do default stuff if no widgets ]
    <?php endif; ?>

    etc etc

  5. MrSister
    Member
    Posted 3 years ago #

    This post sorted it out for me... Time to add status resolved?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.