Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is Sidebar get_sidebar() and sidebar.php?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 666
    Comment on it

    Hello readers !
    Today We will discuss about sidebar.php

    This is one of the best features in WordPress that gave lot of flexibility in theme. Sidebar.php is a template page in your theme directory. It includes some extra links which you cannot show in header menu and footer menu. Admin can customize sidebar.php file. Initially, sidebar were used only as a vertical column provided by a theme for displaying information other than the main content of the web page.

    The side can be categories into two parts :- 1-> Dynamic sidebar, and 2-> Sidebar template.

    Dynamic Sidebar -: Dynamic Sidebar is a dynamic widget area where you can add single or multiple widgets from your WordPress Dashboard (Appearance => Widgets).
    Sidebar Template -: It is a WordPress template which display the content in the sidebar.

    to apply this First you need to register your dynamic sidebar into function.php, this part is very important and you always have to use proper code to register your sidebar.

    Example:- Write this code into function.php file. Argument used for Dynamic sidebar.

    id
    name
    description
    before_widget
    after_widget
    before_title
    after_title

    <?php
    function social_icon_register_sidebars() {
    /* Register the primary sidebar. */
    register_sidebar(
    array(
    'name'          => __( 'Primary Sidebar', 'themename' ),
    'id'            => 'sidebar-1',
    'description' => __( 'Appears in the right section of the site.', 'themename' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>'
    )
    );
    register_sidebar(
    array(
    'name'          => __( 'Secondary Sidebar', 'themename' ),
    'id'            => 'sidebar-2',
    'description' => __( 'Appears in the footer section of the site.', 'themename' ),
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>'
    )
    );
    }
    add_action( 'widgets_init', 'social_icon_register_sidebars' );
    ?>
    

    Way to call dynamic sidebar in your template

    <div id="secondary" class="sidebar-container" role="complementary">
         <div class="widget-area">
             <!--?php dynamic_sidebar( 'sidebar-1' ); ?--><!--This is the code to call dynamic sidebar 1 in your template. -->
         </div><!-- .widget-area -->
    </div><!-- #secondary --><p></p>
    
    
    
    <p></p><div id="secondary" class="sidebar-container" role="complementary">
         <div class="widget-area">
             <!--?php dynamic_sidebar( 'sidebar-2' ); ?--><!--This is the code to call dynamic sidebar 2 in your template. -->
         </div><!-- .widget-area -->
    </div><!-- #secondary -->
    

    Displaying default sidebar content:-

    <!--?php get_header(); ?-->
    
    <!-- write your html code -->
    
    <!--?php get_sidebar(); ?-->
    
    <!--?php get_footer(); ?--> 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: