Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by

Website CMS Source Code Research - Implementation of Sidebar

The widget. Chinese background display name of the CMS of the wordpress website is called a small tool.Includes text tools for adding custom code yourself.
Some tools come with the theme, some are added by you, or the plugins are added for you after you install some plugins.All of these plugins are available, and their information is stored in the option table. We all know that in the first step of WP initialization (mentioned in my previous article "Wordpress Source Code Research - Front-end Running Process") , put these data into global variables.So when constructing the sidebar, the basic process is to read the data, and then display the widgets we selected.
How to do it specifically, we will not talk about the preparation of the data, it is nothing more than querying the database data format.
Let's start from the second step. First, a page gets a request, and it will call the template page to display it.For template pages (index or single), in addition to their own display code for some special information, they also include some general templates (the large template contains sub-templates).Such as header.footer. Of course, our protagonist today is the sidebar. Then these small templates are included and activated.
Our stuff is in the sidebar, and the definition of my template is like this.


That is to say, if there is a function dynamic_sidebar, call this function. If this function returns false (indicating that he did nothing and has no output), then execute the following things.
What's underneath?The following is actually the static thing corresponding to the dynamic word above.That is to say, several widgets by default in the theme.Such as calendars, search boxes, etc.
Of course, how could we not have dynamic_sidebar.This function is located in your wp-includes/widgets.php, do a search and find it.He is the core of the entire widget.
He gets the list of widgets we have selected, how to get it?The data has been prepared in front of him, and it is OK for him to read it.
Then follow the map to find out, foreach each widget to get their specific information. What is the specific information?The most important thing is to have a callback function and its parameters.That is to say, how the widget expresses itself is written in the callback function of the widget.The last is to call the widget in each widget. Bring his parameters.Then the HTML of the widget comes out, output, OK.Finish work.
Source of this article:

Back to Top