With powerful technology, WordPress-based websites can be made into a variety of forms. In addition to requiring WordPress theme developers to be proficient in HTML, PHP, JS, CSS and other technologies, developers also need to master the framework of WordPress theme. Below lizhi125 and you will analyze how WordPress is structured.
The WordPress theme consists of a series of template files, each of which controls part of the theme. No matter on which page of the blog, the frame of the theme is invariable. This is the static part of the theme, which is controlled by header. php, sidebar. PHP and footer. PHP files. We can modify these files to detect the pages we browse and display different contents, such as different navigation on posts and pages. Usually, however, we keep the static part in the same style throughout the site.
The appearance of the website is controlled by the code of the following four parts:
Display blog headers and navigation, also including HTML code
The template file that displays the subject content of the website is called The Loop (more on that later).
The sidebar is controlled by this file. Multiple sidebar themes can add controls to functions. php.
The end of the website and the closing tag of html.
WordPress basic page has Homepage (index. PHP control), Post page (display a complete blog separately, controlled by single. php), separate page (page. PHP control), archive (archive. PHP control), the following are the code files that control these pages.
index.php – home
The index file controls the appearance of the blog homepage. By default, the index file displays the latest blog through a loop, and at the bottom of the home page there is a link to view the previous blog.
single.php – individual posts
This file is used to display the full text of a specific blog that the reader wants to view.
page.php – individual pages
This file controls the appearance of individual pages in the blog.
WordPress allows us to design different templates for different independent pages by:
1. Copy page.php and rename it
2. Add the following code at the top of the file
The code is as follows:
Template Name: YourPageNameHere
archive.php, category.php, tag.php – archives
We can also customize the appearance of archives. If there is no archive.php file, the archive and the homepage are exactly the same; however, we can create a archive.php file to reconstruct the archive page. If category. PHP file is created, the archive page will be overwritten to show only the directory; if tag. PHP file is created, the archive page will be overwritten to show only the label.
Loop is probably the most powerful part of WordPress. It is the result of a looping query. In the loop body, we can output the title of the selected article, blog content, metadata, comments and so on. We can also use multiple loops in a single page. For example, we can use one loop to display the full text of a blog, and another loop to display the title and thumbnail of related articles.
The Loop structure is as follows:
Query post or page
Start Loop // Start the loop
The_title (outputs the title of the post)//title
The_excerpt (outputs the post excerpt)//abstract
The_content (outputs the full post content) // content
The_category (outputs the post categories)//directory
The_author (outputs the post author)//author
The_date (outputs the post date) // date
Other tags (there is a variety of other tags you can use in the loop)//tag
Endwhile; // End the loop
Exit the loop // Exit the loop
Background files for WordPress
WordPress also needs some necessary background files for the theme to work. These documents can be modified according to individual needs, which can greatly change the appearance of the website or provide more powerful functions.
This file controls the output of comments. If you want to provide comments on your blog, put it in loop. Comment.php files can be overwritten by plug-ins (such as Disqus)
Functions. PHP lets us run custom code on WordPress to allow more freedom to modify subject elements.
This is the main CSS file that controls the theme style. The top of the file also contains meta-information about the topic, which is used to provide the title, author and related links of the topic.
Here’s a powerful WordPress profile