I got some tutorial request for “How to Create a Custom single template for a specific category in WordPress” from my blog readers so that I am creating a separate tutorial for this request.
If you are looking to create a custom single page template for a specific WordPress category on your blog or website, keep your close attention in this post as I am going to share how to create custom single templates for a specific category.
Follow the below steps to create a custom single templates in your WordPress blogs.
Step 1) Create or copy content-single.php and create a new file. eg: content-yourCategory.php
Step 2) Open single.php and replace this get_template_part(‘content’,’single’); by the following code:
1 2 3 4 5 | if(is_category('yourCategory')){ get_template_part('content','yourCategory'); }else{ get_template_part('content','single.php'); } |
Note: The parameter “yourCategory” can be your Category ID, Category Title, Category Slug or Array of IDs, names, and slugs.
Hope this tutorial help you to create a custom single post template in your WordPress blog. Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: create a custom single post templates, single post, single post in wordpress, single post template, wordpress custom single post template, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials for beginners