How to create Single Post Template

Some of us want to style differently our single post like the capability of WordPress Page that we can create a custom page.

WordPress have also a code documentation on like the below code.

This code can be put in functions.php of our theme. It select the single post with an ID of 8 and using single_template we can give a location what file or template we can use but this can only use in a single post with that ID.

 

Here is another version I use. What if you want to check if the single post name have a equal single post template in your theme file? I use the code below to check if there is a single portfolio template that will match my current post name or slug and give the file location to single_template to be use.

 

Another style is what if you want to check the category of the custom post type (example for me is custom portfolio post type). I do set a four category and 3 of them would be similar template and the other is different.

I use the code below in my functions.php to check the category and return and gave it to single_template.

This code below help you if you want to get the category of your custom post type.

You can also change the above code if you want to use on built in post type (not in a custom post type). Change the code above on the below code.

I hope this code help other who wants to style differently for specific post.