WordPress template architecture

header.php (website head)
This is a global file (easy IT Note: WordPress generated each page will contain the header.php code), display the page header (header) and navigation menu, also contains the HTML file head code (<head> … </ head>). </ p>
The loop (the page body)
The main content of the site is displayed in the main area of ​​the site through a template file containing the “loop” structure.
sidebar.php (sidebar)
This file controls what sidebar shows. If there are multiple sidebars, you can set in the functions.php file, the sidebar “widgets” content can be set in WordPress management control panel (wp-admin).
footer.php (bottom)
The code that contains the global bottom file and closes the HTML tag (</ html>).
The WordPress theme is made up of a series of files in the template folder (.. / wp-contents / themes / template name /), each of which controls the different parts of the template. No matter which page on the site, some parts of these pages are generally static, controlled by the header, siderbar, and footer files. You can modify these files to see which parts of the site are controlled by which files.
Home page
index.php
index.php is used to control how the home page of the site is displayed. The index.php defaults to a query and displays the loop of the latest article and displays a hyperlink at the bottom to view the previous article.
Alternatively, you can set any page you created in wordpress as the home page in wp-admin> settings> read. In other words, you can set a different page (or url) as a regular blog article as a home page to display, and that page or through the index.php template generated.
Posts (posts)
single.php
single.php is used to control how the article page is displayed. This file contains queries and displays the current article loop.
If you want to display the sidebar (and other elements you want to display), you can specify it in this file. You can also modify the file to make the article page and other pages are different.
Pages (pages)
page.php
page.php controls the display of WordPress Page (page, different and post). You can choose to remove the sidebar or other elements, or add some elements only the page.
WordPress also allows you to create different page templates that are used to display different types of pages. Create a page template is very simple, you just copy page.php, change your favorite name, and then add the following code at the top of the file:
<? php
/ *
Template Name: The name of the page template file you named
/ *
?>
Archives
archive.php, category.php, tag.php
You can use the above files to control the display of various archive class pages. If the archive page template is not archived, the archive page will use index.php as a template; however, you can create an archive.php instead of index.php as the template for the archive class page. If you created category.php, this file will replace archives.php as a template for the categories. If you created tag.php, this file will be preferred as a template for the tag page.
The Loop
The loop may be the most powerful part of the wordpress template. It starts from a query (to decide which article or page data to grab) and has an end loop. The loop shows what depends on your needs. You can display the title of the article in the loop, the content of the article, the metadata (author, date, etc.), custom fields and comments, etc. These elements are the output of an article or page. You can also create multiple queries and loops on an article or page; for example, in single.php, you can create a loop to display the contents of a single article and then use another loop to display under the article content The title and thumbnail of the article related to this article.
Article and page query mechanism
Start the cycle
(Repeat this and endwhile between all the contents until all the relevant content of the article are finished)
the_title
(Output the title of the article)
the_excerpt
(The introduction of the article)
the_content
(The main content of the output article)
the_category
(The name of the output article)
the_author
(The author of the output article)
the_date
(The date of the output article)
other tags
(Can be inserted in the cycle of the various templates used in the label)
Endwhile
(Repeated until all queries have been output)
Behind the scenes of other mechanisms
To make the wordpress theme template work, you also need some important files in the background. You can modify these files according to their own needs, to customize the function of the site and how to display.
comments.php
This file controls how the comments are displayed, and the file contains a loop that queries all the comments for an article. comments.php can be overridden by some plugins, such as Disques, that these plugins can take over the comments of the site.
functions.php
functions.php allows you to add your own php code to modify the core elements of the wordpress theme. Usually this can be used to add multiple sidebars to their own theme, modify the number of characters in the article (excerpt), or add your own admin panel options to wp-admin.
style.css
This is the main template style file for the theme template. At the same time at the top of the file, contains the subject name, the author and your site URL and other related text, so WordPress to know the subject of this information.
other
In addition to the core features of WordPress, other similar plugins, custom fields and wedgets allow you to customize your website further.
Plugins
There are a lot of open source developer community developed a lot of plug-ins, you can add them to your website for free, including e-commerce, slideshow (slideshow), cache and social function.
Custom Fields
The custom field is when you create an article and can be entered in the input box below the article content input box. Through the custom domain, you can create your own options or content, and then you can use them in the theme template or display them. It is often used with thumbnails and used to include javascript code (include).
Widgets
The gadget is a small module for the sidebars. In wp-admin, you can configure the default gadget, you can also add a variety of plug-ins provided by the gadget, or php code. Gadgets typically include content such as search forms, popular article lists, and ad blocks.