Display specific widgets in different area’s around the page

You will want to create a new widget area or dynamic sidebar in your theme’s code. Justin Tadlock has a great tutorial about how to do this, but the basics boil down to this.

  1. Add the widget area declaration in your theme’s functions.php file:

    <?php
    add_action('widgets_init', 'my_register_sidebars');
    function my_register_sidebars() {
    /* Register the 'cartwidgets' sidebar. */
    register_sidebar(
        array(
            'id' => 'cartwidgets',
            'name' => __( 'Cart Widgets' ),
            'description' => __( 'A short description of the sidebar.' ),
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>'
        )
    );
    }
    ?>
    
  2. Then in the appropriate files in your theme (page.php, single.php, index.php, etc.) include code similar to the following to actually show the new widget area:

    <div id="sidebar-primary" class="sidebar">
        <?php dynamic_sidebar( 'cartwidgets' ); ?>
    </div>
    

Those are the basics, but I would highly recommend you read Tadlock’s post, as he’s done a great job of explaining all of the parameters and pitfalls. Doing this, you’ll be able to drag the cart’s widgets into these new sidebars and they will show up, just as WordPress is designed.

Leave a Comment