After the static template of the wordpress theme is written, we can officially enter into the development of the dynamic template of the wordpress theme. The so-called dynamic template is to call the data in the wordpress database through the PHP function and PHP syntax provided by the wordpress program and display it in the front static template of the wordpress website. Any movement of the website can be displayed in the front through the dynamic template. Before developing the dynamic template of the wordpress theme, we need to understand the overall structure of the wordpress dynamic template.
1: Required option for wordpress dynamic template.
The so-called mandatory option is indispensable for WordPress dynamic template. You can follow my action and demonstrate it together.
1. Create a theme directory.
We enter the/wp content/themes/directory under the wordpress program, and create a trans directory under this directory (you can also use other names), which is equivalent to creating a new theme template for the current wordpress website. The template name is trans.
2. Create a template CSS style file.
After adding the template directory, we can see the relevant prompt in the theme interface under the appearance of WordPress background: "Corrupt theme, the following themes have been installed, but are incomplete. The style sheet is missing." (see the following figure).
Create a CSS style file sytle.css in the trans directory. The file name must be style, otherwise it is invalid. This file is necessary for the WordPress dynamic template. If it is missing, an error will be reported immediately.
3. Create a homepage template.
After adding the CSS stylesheet file, let's look at the background theme interface again. At this time, we found another prompt: "Damaged theme. Template missing. Independent theme needs an index.php template file", as shown below:
In other words, the WordPress dynamic template must have a homepage template, index.php. If it is missing, such an error will be reported. Therefore, we will create an index. php file in the trans directory.
4. Add background thumbnail of trans theme dynamic template.
After adding the index.php homepage template, I return to the background theme interface of the wordpress website to check. At this time, there is no error again. This means that the style.css stylesheet file and the index.php homepage template file are necessary for the wordpress dynamic template. If any one is missing, an error will be reported.
However, we also found the following problem: other wordpress theme templates have thumbnails, and you can see the general effect. The trans theme template we created has no thumbnails, and is blank, as shown below:
At this time, we must put a thumbnail into the trans theme directory. The name of the thumbnail must be screenshot, and the suffix can be png, jpg, gif. After adding thumbnails, they will be displayed in the background, as shown below:
These are the necessary options for the WordPress theme dynamic template: style.css stylesheet file, index.php homepage template file, and screenshot theme thumbnail. After that, we can click the "Enable" button to let the current WordPress website use the trans theme template. Of course, if it is enabled at this time, the foreground page will not display anything, and it is a blank page, because we have not put any content and called any data in index.php.
2: Optional options for wordpress dynamic templates.
After completing the required options of wordpress dynamic template, our trans theme template can be used normally. For some WordPress websites with low demand, the entire website may only need one page, such as the Taobao guest theme template, which was particularly popular in the past few years. These Taobaoke websites have no article data, and they only have a simple homepage template, which shows the product links and pictures they got from Taobao Alliance. As long as users click on these products and go to Taobao to consume, WordPress webmasters can earn money.
However, for those of us who are serious website owners, our WordPress website can not only have one page, our website will have many pages. Therefore, when developing WordPress theme templates, we need to create some other template files. This is an optional option for WordPress dynamic templates.
The normal WordPress theme template generally includes the following template files:
Functions. php=>Theme function file archive. php=>List page template page. php=>Single page template 404. php=>404 Error page template header. php=>Header template footer. php=>Bottom template sidebar. php=>Sidebar template search. php=>Search page template searchform. php=>Search form template comments. php=>Comment template
It may also contain the following directories:
Images=>Picture folder js=>JS folder css=>Other CSS style folders include=>Other PHP function folders
Of course, the above optional template files and directories are not fixed. We can choose them according to the specific situation of our website. We can open the official theme of WordPress. Let's open the theme directory of tweetytwenty to see how many optional templates have not been created, as shown in the following figure:
When we open the directory of another official theme template, tweenysixteen, we can see that it basically contains the template files of the optional options we introduced above. As shown below:
Now let's take a look at the ssmay theme developed without stopping. It contains not only the theme template files of mandatory and optional items, but also some other template files, as shown below:
It can be seen that when we develop WordPress dynamic templates, there is no fixed mode. The mode of creating templates is not dead. We should create our own dynamic template files according to the actual situation of our WordPress website and our specific needs. That is to say, in addition to the mandatory items of the dynamic template introduced above, we can flexibly use the others, regardless of the format.