Add a separate sidebar for the page
Today I found one unique tutorial on how to make several sidebars and assign their contents to separate pages in the form of a drop-down list.. A bit confusing but I think, in practice will be clearer.
Step One Adding Sidebars
Open the function.php file in the theme folder and add the code there to create several sidebars in a loop:
$dynamic_widget_areas = array(
/* rename or create new dynamic sidebars */
"Sidebar 01",
"Sidebar 02",
"Sidebar 03",
"Sidebar 04",
"Sidebar 05",
"Sidebar 06",
"Sidebar 07",
"Search Template",
);
if ( function_exists('register_sidebar') ) {
foreach ($dynamic_widget_areas as $widget_area_name) {
register_sidebar(array(
'name'=> $widget_area_name,
'before_widget' => '',
'before_title' => '',
'after_title' => '
',
));
}
}
add_action("admin_init", "sidebar_init");
add_action('save_post', 'save_sidebar_link');
function sidebar_init(){
add_meta_box("sidebar_meta", "Sidebar Selection", "sidebar_link", "page", "side", "default");
}
function sidebar_link(){
global $post, $dynamic_widget_areas;
$custom = get_post_custom($post->ID);
$link = $custom["_sidebar"][0];
?>
echo '
';
?>
Select sidebar to use on this page.
ID;}
update_post_meta($post->ID, "_sidebar", $_POST["link"]);
}
add_action('admin_head', 'sidebar_css');
function sidebar_css() {
echo'
';
}In step two, we add an area to display the sidebar.
I have added this code to the file page.php before posting comments.
Externally, in the widget section, after pasting the code, everything will look like this:
After we insert the widget into one of the areas, you need to go to any page or create a new one and specify it in the drop-down list, what sidebar will be displayed on it.
Also in the settings menu there will be a new item Sidebar Selection Which one, when not needed, can be turned off.
/*

- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.







