How to create different templates for single posts and WordPress categories

WordPress allows users to create different templates pages, but unfortunately does not allow the creation of different templates posts except by creating custom post types, that for the vast majority of users is a relatively complex process of creating different types / styles of posts for your blogs. However, through Custom Fields (custom fields), you can create different types of templates to pages. Again, create custom fields is something that probably the vast majority of non-advanced users will have difficulty playing. Having said that, we are left with few solutions to consider, when the goal is to create simple templates for single posts, as we do for page templates.




If you have a blog and would like to have two different templates for different posts in your blog, or two different templates for two different categories of your blog, know that there are two simple ways to solve this problem, which we explain below this our tutorial.

CREATE TEMPLATES DIFFERENT FOR SINGLE POSTS

 

To create two different templates for single posts WordPress, we suggest you to use the Single Post Template plugin which allows you to easily and conveniently create different custom fields with a dropdown menu to the use of different types of posts. The process of use is very simple, see:

single post templates

Get started by making a search going on “Plugins> Add New” section of your WordPress blog. Perform a search for “Single Post Template” and click “Install Now” to install the plugin and activate it on your blog. We will assume that you activate your plugin. Once activated, go to the next step:

Once you have the plugin installed, what you should do is to create new templates for their single-posts. To do this, we recommend that you copy the code from your single.php file to a new file, and put at the beginning of the header following code:

<? Php
/ *
Single Post Template: [Template Name]
Description: The description and optional. Write if you want!
* /
?>

Please note that if you want your single.php is different from other template you want to create, you need to edit the code of this template and assign it a new different such as single-tutoriais.php, which will be the template to use in their tutorials. Load those files into the board / wp-content / themes / nomedotheme / so that they automatically become active and functional:

Do not forget that these new files necessarily have to have the header that we talked about earlier , otherwise the Single Post Template plugin can not interpret which files are single templates posts .

When loading files, the plugin “Single Post Templates” will automatically understand which single templates posts, and provide a dropdown menu selection within the WordPress articles editor. Below the writing of a new article box will now display the Custom Field to “Single Post Template” that contains all single posts templates you created.

How to create different templates for single posts and WordPress categories

CREATE TEMPLATES FOR DIFFERENT CATEGORIES

 

In case you want to apply the same technique but the categories of your WordPress blog, we will have to use a somewhat different process. We not sought by plugins that do this task in an automated way, because there is actually no need. Follow the steps to create your templates in different categories using WordPress:

The WordPress template hierarchy works following an analysis of logic. It will search for templates by following a certain order, see:

    category-20.php
    category.php
    archive.php
    index.php

This order means that WordPress will first look for a template category-6.php after the category.php, and so on until you get to index.php. This means that create different types of templates in WordPress is actually a super simple and basic process.

To create a different category of template category.php, copy the code that is within your category.php file and save the new file with the category-ID.php name, where the ID means the ID of the category where you want this template is applied. If you do not have a category.php file, you can copy the archive.php or index.php file.

To find the category ID you want, enter the ” Categories” section of your WordPress blog , put your mouse over the category name , and look at the address bar that appears at the bottom of your browser. This address contains the ID = X, X being the ID value in its class . It has nothing to deceive.

categories

So that everything is working properly, you should load into your server, in the / wp -content / themes / nomedotheme / their categories files. In the example above , we have created two different templates for category 1 and category 65, but you can create those good wishes, simply put the category ID in the file name , and the stylization that you want . WordPress will read these templates before reading the category.php , differentiating them all to each other.




LEAVE A REPLY

Please enter your comment!
Please enter your name here