Here it goes. The isertion you can do. The first function is the one called first.
function sidebars_require () {
global $wpdb;
$portfolio_require_query = 'SELECT * FROM duotive_sidebars ORDER BY ID ASC';
$portfolio_require = $wpdb->get_results($portfolio_require_query);
return $portfolio_require;
}
This gets all the sidebars from the db.
function custom_sidebars_initialization() {
$sidebars = sidebars_require();
if ( count($sidebars) > 0 ):
foreach ( $sidebars as $sidebar):
register_sidebar( array(
'name' => $sidebar->NAME,
'id' => str_replace(' ','-',strtolower($sidebar->NAME)),
'description' => $sidebar->DESCRIPTION ,
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
'before_widget' => '<li class="widget-container %2$s" id="%1$s">',
'after_widget' => '</li>',
) );
endforeach;
endif;
} ?>
<?php add_action( 'widgets_init', 'custom_sidebars_initialization' );?>
This one registers all the widget areas that i defined. The metaboxes are made with the help of a tutorial at WPShout.com =>
http://wpshout.com.
function hybrid_post_meta_boxes() {
$sidebars = sidebars_require();
if ( count($sidebars) > 0 )
{
$sidebar_array = array("No Sidebar");
$i = 0;
foreach ( $sidebars as $sidebar)
{
array_push($sidebar_array,$sidebar->NAME);
}
}
/* Array of the meta box options. */
$meta_boxes = array(
'video' => array( 'name' => 'video-thumbnail', 'title' => 'Has video tumbnail?', 'type' => 'select', 'options' => array( 0 => 'No',1 => 'Yes' ) ),
'url' => array( 'name' => 'url-to-video', 'title' => 'Please insert the url to your video.', 'type' => 'text' ),
'sidebar' => array( 'name' => 'sidebar', 'title' => 'Custom sidebar?', 'type' => 'select', 'options' => $sidebar_array )
);
return apply_filters( 'hybrid_post_meta_boxes', $meta_boxes );
}
and now… in the sidebar.php file:
<?php if ( is_single() || is_page() )
{
$sidebar = get_post_meta($post?>ID, "sidebar", true);
$sidebar = str_replace(' ','-',strtolower($sidebar));
if ($sidebar != '' )
{
if ( is_active_sidebar($sidebar) )
{
echo '<ul>';
dynamic_sidebar($sidebar);
echo '</ul>';
}
}
}
?>
Hope this helps.
