Web design

How to create a WordPress template from scratch

fdgdfggFor the umpteenth time, less is more. That’s why the intuitive WordPress has become the most supported content management system (CSM), both by individuals and companies. The fact that this platform is installed in 24% of Internet sites is an undeniable popularity while helping to understand why any web developer who does not work with WordPress is missing out on a great opportunity.

Although there are many reasons for its success and its high acceptance, one of the main reasons is the simplicity, flexibility, and power it offers to developers when creating themes (or templates). In this sense, some programmers point out that, despite working for a CMS, they never have the impression that there is something that cannot be done when creating a blog or a website in WordPress.

To begin to develop our theme, we can add there our folder with the name that we want (in this case, for example, ic-template ). However, keep in mind that aggregating a new directory to the themes folder will not make WordPress understand that there is a new theme that you can use. To solve this problem, we will need at least two new files:

Index.php

This is the file WordPress will call in the case of not finding any template as a start page. It is also a required file in the root of our template.

Style.css

Besides being the main file to define the styles we will use, this is where we will specify the main parameters of the template.

At this point, we already have the minimum files necessary to create a template and WordPress detects it.

For this example, we have just added some of the possible parameters (if you wish, here you can investigate a little more about all the options available to you). Our advice is that you do not just copy and paste the code: try to write it from scratch, change the parameters, put a name for your template, test it, modify the parameters … Check what happens in each situation. We also encourage you to follow these recommendations in any step we take. Dare to experiment without fear!

To round off our template in the theme manager, we would only need to add a screenshot of the final appearance. As our template is still a blank page, to show this step we will incorporate a generic image.

The next step will be to add the rest of the minimum files that we will need to be able to perform this tutorial. At the moment, all file names are marked by WordPress.

Header.php

In this file, we will indicate the header that will be common in navigating the template – such as everything that contains the tag – or the main navigation menu.

Footer.php

As in the case of the header.php file , this will be common throughout the template. In it we will indicate the information that will always be present in the footer (for example the copyright or the links to the legal information).

Sidebar.php

This file is meant to be shown as a sidebar (especially when it comes to a blog) or with widgets ( for example a search engine, a list of categories or the most visited posts ).

Front-page.php

It’s the template that WordPress loads by default as a start page. It is specially designed to be a list ofposts, that is, the cover of a blog.

Home.php

It will be the template that will display WordPress in case you have the option Show staticpage as homepage. This file is intended for cases where the home page is a static page, such as the home page of acorporatewebsite.

Single.php

It is the template that shows a complete post by default.

Page.php

This is the template file that will default to any page we create, as long as you have not specified a template.

Category.php

It serves to show a list of posts of a specific category.

Comments.php

It is the template that we will call inside single.php to be able to add comments to our posts.

Search.php

This template is the one that will display Wordress when a search is performed.

404.php

This is the template that will be displayed when a link is broken or does not work.

Functions.php

This file will allow us to create menu and widget zones, as well as customize some parameters that WordPress brings by default.

At the moment, we create all these empty files. By themselves they do nothing: simply, they are just the files that WordPress will search based on each situation. Some of these files – for example, header.php , footer.php or sidebar.php – will have to be added manually in the templates where we need them.

We already have the necessary structure to create a functional WordPress template, which can be the basis for managing or creating a blog or a web page. The last step we will do is leave the active template. This will be a blank page, but in this way we can begin to see all the progress that we are making.

by http://www.magpress.com/

If you have any questions, please ask below!