WordPress templates: Page templates – .com

In this tutorial we look at the second of the two types of WordPress templates: Page templates, which are individually assigned at the page level.

WordPress templates

First of all, we are going to clarify a concept, and that is that WordPress comes from the American world, where they use a slightly different terminology, which can cause confusion here.

When in this article I talk about templates, I don’t mean themes (topics), that is, the themes that can be changed in the “Appearance” menu, but rather the templates within each theme. Basically in themes, there are two types of template:

  • , that I deal in . They affect any URL of our WordPress depending on the type of information we are seeing and are assigned automatically depending on the file name.
  • Page templates, which I deal with next. These can only be applied to pages (no posts, no categories, no anything else) and they can be chosen from a dropdown when an editor or administrator of the web creates or modifies a page in WordPress. Let’s go there!

Page templates

Unlike , page templates are NOT automatically assigned to a page just because it exists, but must be a user with sufficient capability (Editor or Administrator) assign them to a particular page.

The way to do it is very easy, you just have to go to the page editor and take a look at the “Page Attributes” section, which usually appears on the right of the screen.

There we will see several options, but the one that interests us is the “Template” option, which shows a drop-down menu that allows us to choose between all the templates available in that theme.

It is important to note that page templates depend on theme. So, if the author of the theme in question has created two possible templates, two will appear in that dropdown. And if he has created ten, then ten will appear. It could even be the case that he has not created any, since are optionalso then not even the dropdown would appear.

See also  Slack course - .com

For example, the theme , one of the default WordPress themes, and for me one of the best, offers you three templates:

But where are those three templates? And how do we create them? Let’s see it!

Create page templates in WordPress

We are going to start by looking at where we should place those templates so that WordPress will detect them, and what nomenclature they should follow.

Although they can be placed in many places, the best way is to do it in the folder /page-templates/since WordPress automatically detects and recognizes it, without us having to tell it anything in particular.

So we’ll create a folder called “page-templates” and put a file in there for each template we want to make available to our editors and administrators.

Let’s note that in the screenshot that I am posting, only two files appear, called front-page.php Y full-width.php. But instead, in the previous screenshot we see that we can choose three templates:

  • default template
  • Cover page template (corresponds to front-page.php)
  • Full size page, no sidebars (corresponds to full-width.php)

So what about the “Default Template”? What template are you using? Well, that will depend on the existing ones. In this case, in this same capture we can see a file called page.phpwhich is what the template provides.

And speaking of file names, which ones should we use? Well, just as in the case of those they had to follow a very strict nomenclature, here it is a free will. We can put the name we want. In this case, it has been chosen front-page.php Y full-width.phpbut they could have put home-page.php Y full-page.php and everything would work the same.

See also  Premiere Course #4. Video effects and transitions - .com

The only thing to avoidis to use page-{something}.php, since if we do it like this, WordPress will think that this is a code and will apply it directly to the corresponding page. And exactly the same with the rest of the names reserved for the . So to avoid problems, we can use names in Spanish, like home-page.phpor underscores, like page_{something}.php.

And now we come to the creation itself. The most convenient, easiest and fastest way to create a template for a page is simply duplicate the page.php file, rename it, and move it to the /page-templates/ folder. In this way, we will have a “base” to start modifying quickly.

What is the only “required” modification we need to make to that file in order for it to be recognized as a template and to be placed in the dropdown by WordPress? Well, just add this line of code:

With this we have everything ready. Obviously you have to change the “Name of the template” to what you want, otherwise, that will appear precisely in the drop-down, as we can see in this screenshot.

And now, we can start modifying all the code we want from that newly created file. As we start from the code that was in page.phpIf we don’t change anything, the appearance of the page with that template will be the same as the default template. So, we simply have to add or remove what we want.

For example, this is the basic code of page.php of the theme Twenty Eleven:

See also  Tax course for SL - .com

Now let’s imagine we want to create a page template without a sidebar. Well, we should simply delete line 28 like this:

And done. We already have a template that we could call “Without sidebar” that any editor or administrator can easily select from the dropdown. And obviously, creativity to power! We can put all the code we want both at the content and design level.

If you want to know more about the code that you can enter, take a look at the . And if you want to know more about how to put a “class” in that template to make CSS modifications, you have the .

conclusion

WordPress allows us to create as many page templates as we want for editors and admins to select from a dropdown when creating or editing a page.

These templates (only available for pages) They can be used multiple times, on as many pages as we want, without any limit. So, we can create one and reuse it on all the pages we want.

Finally, remember that they are optional and depend on theme that we have active If the person who has done it has not created any, we will not have that dropdown.

And that is all friends. I hope it was interesting and that you learned something. And if you still have any questions, you can contact us through the “Support” tab of the subscribers. See you in the next tutorial!

Loading Facebook Comments ...
Loading Disqus Comments ...