Ask questions about WordPress courses

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' => '
', 'after_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]; ?>

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:

sidebar-bar wordpress

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.

select-sidebar выбрать какой сайдбар будет отображаться на странице wordpress

Also in the settings menu there will be a new item Sidebar Selection Which one, when not needed, can be turned off.

sidebar-bar-menu - отключить область сайдбара wordpress


Купить хостинг WordPress
Репетитор по wordpress
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal