Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by mi@mgsh.com.cn

Website production theme production sidebar sidebar.php

The previous two tutorials talked about extracting the common code at the head and the bottom into a separate file. For the same reason, for the blog theme, the sidebar is basically common (maybe some pages are different), generally It is said that we also extract the common code of the sidebar and put it into a separate file. Of course, the function of the sidebar is not only this. With the sidebar file, you can add gadgets to the sidebar from the background through the code. .
Create a new sidebar.php file in the theme folder content\themes\Aurelius, and then open the index.php file with an editor to cut out the sidebar code inside and paste it into sidebar.php. The sidebar code is as follows:

Categories So who are we? Philosophy History Jobs Staff Clients Archives January 2 December 4 Novemeber 4 October 4 September 4 August 4

After cutting, add the code to the original position of index.php:


You can see that this function is very similar to the function to get the head and bottom. The get_sidebar() function will load the sidebar.php file, but the get_sidebar() function can add parameters.
such as:


This code loads sidebar-1.php. Some people hope that the sidebars of each page on the website, such as the home page, inner page, category page, etc., are different, so they need to have multiple sidebars. At this time, this function must be given. Added parameters.
In order to adapt to the WordPress program, we also need to make some fine-tuning of sidebar.php, download the new style sheet style.css, and replace the style.css in the Aurelius directory. Here is the download link of the new style.css file on the pandanus blog:
Edit the sidebar.php file and delete the code inside, because those are static, we need to set the gadget from the background, so delete it and change it to:

Categories latest articles  ' . get_the_title(). ' '; } $post = $posts[2]; ?> Tag Cloud Article Archive 

Code alone is not enough, function support is also required. Now create a new file functions.php under the theme folder to put the function code, and add the code in it:

//Register sidebar if ( function_exists('register_sidebar') ) { register_sidebar(array( 'name'=>'front page sidebar', 'before_widget' => ' ', 'after_widget' => ' ', 'before_title' => ' ', 'after_title' => ' ', )); }

Register a sidebar by adding a function. After adding this function, your theme supports the sidebar function. You can see the sidebar option on the background widget page.
Source of this article: WordPress Theme Creation Tutorial www.ashuwp.com/courses/simple/109.html

Back to Top