2015-01-25

In this article, we will create a simple template for a minimal WordPress. To begin, I want to note that there are two variants of writing templates for WordPress. If you want to make changes to an existing template, add to it or change the functionality, the easiest option is to create a child template. This pattern may consist of only one file css, announcing a new topic styles, and all other files will be taken from the parent theme. This is the best option to create new templates for beginners, as well as in the case if the subject is a modification of an existing one, because in this way you can avoid mistakes and create a truly properly working pattern. WordPress Themes must meet all the requirements stated in the Code, and one of these requirements is as follows: all the code on the subject should be added meaningfully.

Creating a child theme

To do this, create a directory with the themes folder with the name of the new theme, and inside the file style.css. To the theme of a work, you need to issue a comment at the beginning of the file. Here is an example of the title theme, which is a subsidiary of the standard topics Twenty Fourteen:

Change the data from this example and its further possible to write css code of your theme. To subsidiary theme work, you must supply the parent topic with her.

Child themes can declare your own templates and their functions, as well as overwrite existing ones. Besides the parent theme can declare their unique hooks, which can use child themes.

Creating a theme from scratch

We will create a theme that consists of only two files:

style.css

index.php

Stylesheet

This file is necessary to correctly fill in the title, it is from this file WordPress Learn all about the new theme:

Theme Name – the name of the new theme. For placement on wordpress.org it must be unique among all those of this site, written in English and does not contain the word ‘theme’, ‘WordPress’ or advertising.

Theme URI – site address topics. Must point to a page or a website dedicated to this topic.

Description – description of the topic.

Author – name of the developer.

Author URI – the developer’s site.

Version – version.

Tags – the keywords used in the search filter site wordpress.org.

Text Domain – is used to translate the name of the theme to replace spaces with ‘-‘.

License: GNU General Public License v2 or later. – All WordPress theme as she was licensed under the GPL license.

License URI: – License is referred or file.

As a result, we obtain the following comment:

Comments are always located at the beginning of the file style.css.

Index.php file

The only file our most simple theme is index.php. When WordPress wants to display a particular page on your site, it is looking for a suitable template from the most specific to this type of content. For instance, at the moment the user has gone on page site, then WordPress will check whether there is a pattern called page-ID.php, where ID – a unique ID page, not finding the file, it will check for the file <page.php>, if and it does not, it will turn to file Index.php, which lies at the root of the entire hierarchy of templates WordPress. Template name a lot, I will not list them, if you’re interested, you can see the full list in the code. All of the code of our theme will be contained in a single file and this file will display the page record, search results and all archives. This template is made ​​for the purpose of learning to show how looks the simplest theme WordPress, which consists of two files. So, the file begins with a comment in the style of the standard:

Here we specify the purpose of the template and version.
Next comes the information that is usually placed in the header, doctype and meta tags:

Ways to js and css files, we do not prescribe manually instead you must use the functions WordPress, because these url vary on different sites. Before the tag is classified mandatory hook wp_head, if this is not done, the majority of plug-ins will not work with this template. cling to body classes:

The next section of code displays the cap. Here we show the name of the site that the user enters in the Officers theme WordPress, search box, and the main menu:

Next, you need to show the content of the site. It occurs in a series of WordPress, it gives us all the information related to the user-requested url address. Beginning of the cycle:

Within this cycle, we have full access to information related to the current record for future reference use standard functions WordPress.
This line displays the classes related to the current record and its ID:

And in the following checks are performed: whether the current page is selected, and at the same time whether we are on the page a list of all records and is not divided on whether it is a lot of pages:

The fact that WordPress is possible to stick a record at the beginning when the list of all pages and this possibility should support each topic, you want to select a favorite record once, so these lines, we need a template WordPress.Next, we identify it:

This option does not support threads translation, and all the words I write just in Russian. So should not do.Function _e () to translate the phrase into another language, the second parameter specifies the identity of her, which was previously associated with the file transfer, it usually happens in the file functions.php, which we simply do not.
Let’s go back to our pattern, we print on the post title if it is single page or post, just show it, or do it from the link to the page, and then a list of all the categories and tags that are associated with this record:

Now it is time to show the content. To search results will display only a brief description. And if the page is divided into several, and then show the navigation on pages:

At the end of the page deduce the date of publication and name of the author and a link to edit the recording, which will be displayed for the registered user with the rights to change the recording:

End of cycle:

We show pagination:

Next is a piece of code that displays information if no blog pages or search results yielded nothing:

Well, the basement, where we show the traditional link to the official site of WordPress:

Here, at the very end of the site, announced the hook wp_footer, this ad is imperative and is used plug-ins, for example, to load the script.

The whole file full:

The final form of the template

I added a few lines style.css file to give the appearance of a pattern similar to the site. Here’s what came of it: The original css:



Note: css file is not complete, and is used only as an example.

Which in this template is no

Random header.

Arbitrary background.

Thumbnails record.

Support the translation into other languages.

Style Editor TinyMCE.

Sidebar for widgets.

Widgets themselves.

Hierarchical menus.

Additional options for the Officers WordPress.

Arbitrary taxonomies.

Fonts Google.

Different formats for recording.

Additional templates for pages.

RSS.

Comments.

Hooks WordPress.

These are some of the features that can include theme WordPress, which immediately come to mind. Our template is very simple and does not use a lot, but something we should start, and this pattern is written from scratch and is more likely to study WordPress, than for use in the original version. Taking this theme as a basis, we can see that yes, indeed WordPress template may consist of only two files, then, realizing what we need to add these or other opportunities, change the template to suit your needs or desires. In order to understand how and what is happening inside of WordPress should be familiar with the concept of hooks. These hooks are declared in the source code and WordPress themes and widely used plug-ins, search for the desired functions, actions and filters is conducted mainly in the source WordPress, she herself is an open source and developed by volunteers. Anyone can join the team on the development of WordPress doing, for example, a new template and place it on the site wordpress.org.

Note

If you have any comments or additions to this material, I’ll be glad to hear them in the comments to this article.When you create a template was used the source code of the standard WordPress.

The post How to create a Simple WordPress Template appeared first on WBD.

Show more