988 posts It's in the pipeline!
  • Elite Author
  • Exclusive Author
  • Europe
  • Has been a member for 5-6 years
  • Bought between 100 and 499 items
  • Referred between 200 and 499 users
  • Envato Studio (Microlancer) Beta Tester
+2 more
purethemes says
Exactly
            $sidebar = get_post_meta($post->ID, "whichsidebar", $single = true);
            if ($sidebar) {
                if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($sidebar) ) : ?>

                <?php endif;
            } else {             {
                if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Standard sidebar") ) : ?>

                <?php endif;
            }
</pr?>
1383 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Serbia
wpCanyonThemes says

Pretty similar to what they said.

Basically it works using a custom field and a foreach.

The register loop

This goes into functions.php or (sidebars.php in my case, keeping it organized :P )

global $wpdb;

$widgetized_pages = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'jw_sidebar'"));

if($widgetized_pages){

    foreach($widgetized_pages as $w_page){

        $widget_id = strtolower(str_replace(' ', '_', $w_page));

        register_sidebar(array(
            'name' => $w_page,
            'id'   => 'jw_widgetsection_'.$widget_id,
            'description'   => '',
            'before_widget' => '<div class="widget %2$s" id="%1$s">',
            'after_widget' => '</div><div class="hr"></div>',
            'before_title' => '<h6>',
            'after_title' => '</h6>'
        ));

    }/* For each user created widget END */

}/* If there are user created widgets END */

Just change the register_sidebar settings to what you need and the custom field name (don’t use mine :) ).

Notice: Don’t forget to put that up in a function and use add_action to attach it to “widgets_init”.

Which one should it use?

This is in sidebar.php (and sidebar-blog.php and every other sidebar-....php)

$post_custom = get_post_custom($post->ID); 
/* Get special sidebar if it exists */
if(isset($post_custom['jw_sidebar'])){ $sidebar_name = $post_custom['jw_sidebar'][0]; }else{ $sidebar_name = 'Page Widgets'; }
if (function_exists('dynamic_sidebar') && dynamic_sidebar($sidebar_name)) : else : /* the rest isn't important */

And that’s all.

Of course make a custom meta box so the user has some kind of system. A simple text input and a select (with the custom sidebars already made) is enough.

That’s all.

P.S Don’t have MSN , got Skype. Just search for wpcanyon [at] gma…

380 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 100 000 and 250 000 dollars
celtathemes says

@wpCanyonThemes, Thanks for sharing! Why dont you release this functionality as a plugin? Just an idea.

1383 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Serbia
wpCanyonThemes says

@wpCanyonThemes, Thanks for sharing! Why dont you release this functionality as a plugin? Just an idea.

Will do so for sure, we have some rebranding planned and a nice website where we’ll share all kind of freebies, tutorials, plugins and other cool stuff, so that’ll probably be the first plugin there.

753 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Author had a Free File of the Month
  • Exclusive Author
  • Has been a member for 5-6 years
  • Bought between 1 and 9 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
AdamGold says
Very nice code wpCanyonThemes, as an addition here’s the code to display all of your current plugins
        $sidebars = get_custom_sidebars();
        if( $sidebars ) {
            foreach($sidebars as $sb) {
                ?>
<strong> <?php echo $sb['name']; ?> </strong>
                <br />
                <?php
            }
        }
function get_custom_sidebars(){
    $sidebars = get_option('my_sidebars');
    if($sidebars)
        return $sidebars;

    return;
}

// Deleting the sidebar
    $sidebars = get_custom_sidebars();

    unset($sidebars[ $_REQUEST['delete'] ]);

    update_option( 'my_sidebars', $sidebars );
//You should pass the sidebar name you want to delete via POST or GET.
212 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Portugal
shaki says

You guys ROCK . :)

2952 posts
  • Attended a Community Meetup
  • Author had a File in an Envato Bundle
  • Author had a Free File of the Month
  • Bought between 100 and 499 items
  • Contributed a Blog Post
  • Elite Author
  • Exclusive Author
+5 more
DDStudios says

@wpCanyonThemes

Just added you on skype. I think I’ll need help implementing this code ;)

by
by
by
by
by
by