User chat (Front End). How WordPress accesses the various templates in the current theme

A WordPress template consists of a set of files. Knowing what a particular file is responsible for, you can edit the theme to suit your own needs, with at least basic HTML, PHP and CSS skills. And if you don’t have such knowledge, then you can find out using the built-in tools.

In this article I will tell you about files WordPress themes, and what they are responsible for.

When loading each page of the site, the certain files, each of which performs its own function. Some files must be used throughout the site, on every page, while others can only be used in certain parts of the site.

WordPress template files are like the building blocks or building blocks that make up a page. For personalization specific page you can delete or use, as well as change this or that file.

Below is a table that describes the main WordPress template files.

Main files
Index.phpIs the main thing in the template. It contains code that is responsible for the location and loading of other files on the page. This file also generates the main page in the browser.
page.phpGenerates single pages.
single.phpGenerates single records.
sidebar.phpGenerates sidebars on the site, side columns.
header.phpCreates a header on the site. As a rule, it contains a logo and a navigation menu.
footer.phpCreates a site footer or footer - this is the bottom part.
functions.phpRegisters functions such as the appearance of saybars, menu areas and others.
style.cssA style sheet that specifies the rules for appearance all site elements: text fonts, sizes, colors of elements, their relative position, etc.
Record output files
category.phpDisplays posts from a specific category.
tag.phpDisplays records of a specific label (tag).
author.phpDisplays posts by a specific author.
archive.phpDisplays records for a specific date, that is, archives of articles.
Additional files
comments.phpDisplays comments and a form for adding comments.
search.phpDisplays results on the website for a query in the search form.
attachment.phpOutputs the attached file.
404.phpResponsible for displaying the 404 page that appears when clicking on a non-existent link.

The above list of files is optional. Some of them may be missing in certain themes, and certain templates may be supplemented with other files.

File hierarchy

Visually and in a simplified version, you can represent the hierarchy of WordPress template files as in the image below. Remember that topics may vary from person to person and things may be different.

WordPress Template File Hierarchy

How to Edit WordPress Template Files

Editing WordPress template files allows you to change the theme in more detail and depth than was intended by the developer himself. For everything to work out, you need to understand the hierarchy and functionality of the files themselves, as well as have at least basic knowledge of languages PHP programming, CSS and HTML.

Even if you know programming languages, before editing any file, be sure to do it backup copy so that in the event of an accident the theme can be returned to working condition.

WordPress template files can be edited directly in the console. To do this, go to the “Appearance” item and select the “Editor” sub-item. Here in the left list there will be available files, and on the right - the contents of the selected file. This editor does not support syntax highlighting. Therefore, it is more convenient to copy the contents of the file to some third-party editor, for example, NotePad++, change it there, and return it back.


Hello everyone and welcome to the easiest to understand site about creating your own online business. Let's continue exploring WordPress themes. Today we will analyze the composition of the topics and how you can edit this or that information in the topic.


As you remember, the theme is the visual shell of our site, and it consists of many separate files, where all the parameters of the theme are written, reactions, various actions, any picture, button, etc. will be located in the folder with the theme. First of all, we need to understand where all this goodness is located.

Go to your admin panel and select file manager, and the name of your site (the approximate path will look like this: /site/public_html/wp-content/themes/name of your theme), the picture below shows us a bunch of folders and files. This is what our WordPress theme consists of:

The structure of a WordPress theme (template), a clear example of a WordPress template

In addition to the fact that our WordPress theme, how the constructor is assembled from various files, it is also in its entirety, already ready, has its own structure, and if we know this structure, we can, with a little knowledge, edit the topic for ourselves, make certain changes.

Any WordPress theme has basic elements that are responsible for displaying information in various parts. For example, the Header.php element is responsible for displaying information at the top of our theme; in common parlance it is called a header.

The pictures that are at the top, the menu, the title of the page Title, all this and some other elements belong to Header.php That is, if you want to change the title, change the picture, or do something else at the top of your site, you need to go to the menu item Header.php , or open this file, which is present in your theme folder, with a special editor.

You just need to know a little language html and entering correct code Easily change the header design, menu, etc. Please note that the header.php of a WordPress theme is the only one for the entire site, that is, it will be displayed everywhere, no matter what page you open.

Sidebar.php or another way is responsible for displaying information on the side side panel. It is also consistent across the entire WordPress theme. Depending on the theme, the sidebar can be located on the left or right, and can have several columns.

In theory, for making money, it is most interesting to have 2 columns in the sidebar, for more advertising, but in principle, if your site is popular and a competent approach, you can make good money with 1 column)

The footer or footer is visually responsible for the bottom of our site and is responsible for the Footer.php element. The footer is also a permanent part of every page. People usually add whatever they like to the footer, Lately There is a fashion for wide footers where they add not only the words that all rights are reserved, but also meta tags, a story about themselves, comments on articles.

In the figure below, under number 1 is the template Header.php, under number 2 is the sidebar, and number 3 is the footer or footer of our theme:

In this article you will learn what a website developed on WordPress consists of, as well as what this or that component of the Internet project is used for. Each of the described parts should be on any website.

Understanding what a website consists of allows you to better understand the essence of webmastery. And also this knowledge will help you accept correct solution develop and change the site if necessary.

All parts of the site can be divided into two groups – technical and SEO parts.

Technical parts of the site

To understand what a website consists of, you need to start with the technical part, that is, with those elements of the project that ensure its functionality.

Templates, themes

Templates or themes are the design of a website. It is a set of files that convey the intended appearance to users' browsers.

Templates in WordPress are stored in the wp-content/themes folder. They can be installed from the console in the “Appearance” item, “Themes” sub-item. How to choose the right template on the site is described.

Plugins

Plugins are add-ons that expand the functionality of a website. Without them, it will not be possible to create a full-fledged project. Most plugins are distributed free of charge (as are themes and WordPress itself). Therefore, there are no great difficulties in using them.

Database

Since we started talking about what the site consists of, we should also mention the database. A database is a table that stores all articles, pages, settings, user logins and passwords. Despite the fact that the user does not have to directly interact with the database in any way, this element of the site is extremely important.

You can access the database from the hosting control panel, from PHP applications MyAdmin. However, it is not recommended to somehow change the database settings for beginners who do not yet have experience.

SEO parts of the site

When talking about what a website consists of, we should also mention those components that ensure its promotion on the Internet, that is, the SEO part. In WordPress terms, this includes pages, posts, and media.

Pages

Pages are static elements on which you can place information that is often needed by users, for example, contact form, an article about the project, etc.

Posts

Posts are dynamic elements. They are suitable for publishing articles in them, that is useful materials. Posts are the most valuable elements of a website for promotion.

Multimedia

Multimedia files - images, video and audio are also needed on the site, and they also play a positive role in the promotion and perception of the material. This especially applies to images.

Today I want to talk about design themes for a WordPress blog (read). Knowing how any topic is fundamentally structured, it will be easier for you to add to it necessary changes or additions. In principle, there is nothing complicated about this, but at first a number of confusion and questions may still arise, so I will try to tell everything as detailed and accessible as possible.

Download theme for WordPress You can do it for free, for example, from here. After you have downloaded the template, you need to unpack it. You will then need to access your site via FTP protocol and copy the resulting folder with the WordPress theme after unzipping to the directory:

How is a WordPress theme structured and what templates does it consist of?

The Current Theme area will display the one you are using. this moment. Our newly added one should appear in the “Available...” area. By clicking on the "Preview" button you can see what it will look like this template in relation to the content of your blog.

To apply the theme you like, you need to click on the “Activate” button next to its preview. As a result, the thumbnail will move to the “Current...” area, and the appearance of the blog will also change in accordance with your wishes.

Everything seems simple and clear. But it is unlikely that you will find a theme for WordPress that would meet all your requirements one hundred percent. Surely you will want to change, remove or add something. But how to do that? It’s not particularly difficult, but for this you need to know and understand how it works, what files (templates) it consists of, and what exactly each of these files is responsible for.

The topic always includes specific set templates that are responsible for the design individual areas any web page of your blog. It turns out that all web pages are assembled from separate files, like a constructor.

Some of these files, such as HEADER and FOOTER, are used on all blog pages, others are used only in certain cases. Schematically, the structure of theme templates in WordPress can be depicted something like this:

HEADER is responsible for displaying the header of all pages, i.e. top part. It also forms meta tags that are included in HTML header code of all web pages - header TITLE pages, the Russian language encoding is set, the path to the style sheet file is specified, which should be connected to set the design of this web page, etc.

As I already wrote in the article, you can replace sections of code in HEADER with unnecessary calls to the database with static HTML code in order to remove extra load to the server when generating web pages.

The header, also generated in HEADER, remains the same for all web pages, but the content of the blog content area is generated by different theme templates, depending on what kind of content is displayed. Let's look at this in more detail:

  1. for displaying content home page the INDEX file responds
  2. SINGLE is responsible for displaying pages with articles
  3. When displaying the contents of a temporary archive of articles (by year and month), when displaying the contents of an archive of tags (tags), as well as when displaying the contents of categories, usually the same ARCHIVE template is used
  4. SEARCH is responsible for displaying blog search results
  5. the PAGE file from the folder with the current theme is responsible for displaying static pages (for example, “About the blog”)

The FOOTER file is responsible for forming the footer in WordPress (footer, bottom of the web page). Usually it displays the name of the blog with the words that all rights are reserved (this is called copyright and with the help of it). You can also add visit counter code to FOOTER (for example), if you use them on your resource.

The SIDEBAR file is responsible for displaying the sidebar (sidebar - sidebar of a WP blog) to the right or left of the central part of the pages. In addition to SIDEBAR, each specific theme can use several more sidebar templates. In my case, the sidebar is first formed from the SIDEBAR code, but then SIDEBAR1 and SIDEBAR2 are called from it, which form its two-column extension (they are now disabled).

Knowing the structure of the theme you are using, you can easily understand which file you will need to make changes to get desired effect. Moreover, there are possible use cases different templates depending on which ones are available. At first it seems confusing, but after reading the end of the article you will understand that everything here is quite logical and thoughtful.

An example of connecting templates from the theme

The easiest way is to talk about the procedure for using templates to display a particular blog page using an example. Let's say that a visitor opens a web page with a list of articles of some category (heading). Which file from the current theme folder should be launched?

Based on what has been written above, you can conclude that to display the content of this web page WordPress engine ARCHIVE must be used. In this case, you will be only partly right. Yes, indeed, this template will be used to display categories, but only if a number of conditions are met.

Let's look at the actions of WordPress when a visitor follows a link leading to a category. First in the current theme folder:

Wp-content/themes/title_

this engine will look for the file that is responsible for the output of this particular category. And because they are identified by ID, then he will search for CATEGORY-n. Here N is the ID number of this category (). But such a file can only appear in your theme folder if you yourself created it specifically for this category.

But if you did not do this, then WordPress, not finding such a file (for example, CATEGORY-12), will look for a CATEGORY that is already common to all categories (regardless of their ID). If such a file is also not found, then it will already look for a common template for outputting all archives called ARCHIVE.

It will most likely find ARCHIVE in the folder with your current theme, but if something terrible happens - even if it doesn’t exist - WordPress will be forced to use the main file called INDEX.

This is how it turns out logic for using templates in WordPress. Now, armed with the example above, let's look at how to use them for different blog web pages.

How WordPress accesses the various templates in the current theme

Let's consider everything possible options web pages that are usually used and the sequence of using files available in the theme folder:


Good luck to you! Before see you soon on the pages of the blog site

You can watch more videos by going to
");">

You might be interested

How to automatically add Alt attribute V Img tags your WordPress blog (where they don’t exist) Free themes and templates for WordPress - where you can download them Smileys in WordPress - what smiley codes to insert, as well as the Qip Smiles plugin ( beautiful emoticons for comments) How to disable comments in WordPress for individual articles or the entire blog, as well as remove or vice versa enable them in a template
Reducing memory consumption in WordPress when creating pages - WPLANG Lite plugin for replacing the localization file How did you arrange the display of posts on the main page and in WordPress categories?
Headings of articles H1, H2, H3 in WordPress, as well as methods of displaying categories (the_content, the_excerpt and others)