Another way to add customizable gadgets

WordPress twenty-three 5.6K Reading mode
abstract When making the HotNews pro2.6 upgrade, we integrated the functional modules on the side into the WP gadget and started to use the method (see here for detailed methods). There is a defect that the customized gadget after use cannot be used again after the page is refreshed

When making HotNews pro2.6 upgrade, integrate the functional modules on the side into the WP gadget, and start using the method( Detailed methods can be found here )There is a defect that the customized gadget after use cannot be used again after the page is refreshed. Last Reference This tutorial for foreigners And official Codex After simplification, the final code is as follows:

  1. <? php
  2. class  news  extends  WP_Widget{
  3.     function news(){
  4. $widget_options=array ('classname '=>'set_contact', 'description'=>'Customize the latest articles');
  5.         $ this ->WP_Widget(  false , 'Latest Articles', $widget_options);
  6.     }
  7.     function widget($instance){
  8.         include( "widget/news.php" );
  9. ?>
  10. <? php
  11. }
  12. }
  13. add_action('widgets_init',create_function( '' , ' return  register_widget( "news" );'));
  14. ?>

Multiple custom widgets can modify the news text and the imported custom code file. The advantage of this official Widgets API method is that the custom widget can be reused.

The original tutorial code has many function setting options, which are somewhat complicated and have been simplified by me. If you want to further enhance the functions of the gadget, you can refer to the following article to try to toss about.

WordPress Development for Designers Part 1: How to Build Custom Widgets for Your Themes

Widgets API

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
Comments twenty-three    Visitors seventeen    Author five
    •  Bakhtiyar
      Bakhtiyar three

      The sofa is mine. Hey hey, Brother Bird has been updated recently. Come on...

      •  Eternal Tower Base
        Eternal Tower Base three

        I've never sat on Brother Bird's sofa

        •  Hm China
          Hm China two

          Loading is a bit slow, Brother Bird took care

          •  Data recovery training
            Data recovery training four

            It's really good

            •  E Perspective
              E Perspective three

              Brother Bird, can the 2.5 theme support the gzip plug-in?

              •  Yuannuono
                Yuannuono four

                After I use your theme, enter one of the categories, such as http://ynono.com/category/keep-beautiful On the page, I found the prompt Warning: include (includes/random. php) [function. include]: failed to open stream: No such file or directory in/home/aonion/domains/ynono. com/public_html/wp content/themes/HotNewspro/archive.php on line 97

                Warning: include() [function.include]: Failed opening ‘includes/random.php’ for inclusion (include_path=’.:/usr/local/php5/lib/php’) in /home/aonion/domains/ynono.com/public_html/wp-content/themes/HotNewspro/archive.php on line 97
                Can you take a look at it for me

                  •  Robin
                    Robin

                    @ Yuannuono It seems that you have used the previous version of this theme, and the theme still has the residual code of the previous version. Click to restore the default in the theme setting, and pay attention to backing up the content entered previously

                      •  Yuannuono
                        Yuannuono four

                        @ Robin As you said, the theme setting has been restored to the default and reset again. Why is this still the case

                          •  Robin
                            Robin

                            @ Yuannuono Open the archive.php deletion of the topic

                            <!–  end: navigation –>  
                            And

                            <!–  end: bottom –>  
                            Code between

                      •  aas
                        aas one

                        Good, learn

                        •  Floating clouds
                          Floating clouds one

                          Brother Bird, let me ask you something. Is the wp version you installed the official Chinese version or the official English version+Chinese language patch (unofficial)
                          Thank you!

                          •  Luo Ping
                            Luo Ping one

                            Brother Bird, I can't find how to add the microblog at the bottom. thank you

                            •  Dreamer
                              Dreamer three

                              Brother Bird, I set the latest comment as a gadget, but the display is a bit abnormal, always showing a person's face

                                •  Robin
                                  Robin

                                  @ Dreamer Yes, not all codes can be integrated into gadgets

                                •  The night is beautiful
                                  The night is beautiful zero

                                  add_action(‘widgets_init’,create_function(”, ‘return register_widget(“news”);’)); How to expand this? It is not allowed to copy it once. Change news to news, and post is also not allowed. Solve.

                                 anonymous

                                Comment

                                Anonymous netizens
                                 :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

                                Drag the slider to complete validation