Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Wordpress function the_widget()

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 470
    Comment on it

    Welcome to Findnerd. Today we are going to discuss one of the wordPress function of widget api, the_widget(). Basically wordPress widget is nothing but a PHP object. Whenever widget() function is called,  data displays on the page. If you work in wordPress then you have used the widgets through sidebar but most of the time we need to display the widget outside the sidebar then we have to use this function to display the widget so we start with the basic settings.

     

    the_widget()

     

    Syntax the_widget( $widget, $instance, $args );

     

    Parameters Description
     $widget(string)

     This is required one. It is widget class name. There are many in-build widgets available in wordPress so you can use  in-build widgets class name to display. in-build classes are

    Widget Archives : WP_Widget_Archives
    Widget Calendar : WP_Widget_Calendar
    Widget Categories : WP_Widget_Categories
    Widget Links    : WP_Widget_Links
    Widget Meta     : WP_Widget_Meta
    Widget Pages    : WP_Widget_Pages
    Widget Recent Comments : WP_Widget_Recent_Comments
    Recent Posts : WP_Widget_Recent_Posts
    Widget RSS : WP_Widget_RSS
    Widget Search  : WP_Widget_Search
    Widget Tag Cloud  :   WP_Widget_Tag_Cloud
    Widget Text : WP_Widget_Text
    Widget Navigation  : WP_Nav_Menu_Widget

     You can also use custom created widget to display. Default value is set to none.

    $instance(string/array)  This is optional one. It is used to set the settings for the widget.
    $args(string/array)  

    This is optional one. It is used to pass the argument of widget. Default value is empty array. If it is not set then default argument will be active.

    before_widget : text/html before the widget. Default is set to <div class="widget {widget's classname}">
    after_widget  :  text/html after the widget. Default is set to </div>
    before_title  :  text/html before the widget title. Default is set to <h2 class="widgettitle">
    after_title :     text.html after the widget title. Default is set to </h2>

     

    You can check the details related to different parameters for this function. Now we are going to take a small example.

     <?php the_widget( 'WP_Widget_Archives', array('title'=>'Previous Data','count'=>1,'dropdown'=>1)); ?>

    In above code we are trying to display the widget archives and we set the title and show the post count or not, show in dropdown or not. 1 means show post count as well as show in dropdown. Default values are 0.

    As the above we can use other widget as well and can show your custom widget as well. Thank you for being with us.

 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: