I have single.php file and it set the default template for my posts.
How can I set more views/templates for posts in specific category?
I saw that there are plugins, but plugins aren't up to date.
Can i do this without any plugins? I know how I can do this for pages but no for posts.
Thanks for help.
It's simple.
look at https://codex.wordpress.org/Function_Reference/in_category
if (in_category('myCategory')) {
// show template for this category post
} elseif ( in_category('2ndMyCategory')) {
// show template for 2nd category post
} else {
// show template for deafault post
}
Try this, I hope it will be useful.
您还可以通过修改查询,添加'category_name' => 'insertcategoryname',
来获得具有特定类别的帖子。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.