我有single.php文件,它爲我的帖子設置了默認模板。如何爲特定類別的帖子設置其他temlates/view?
如何爲特定類別的帖子設置更多視圖/模板?
我看到有插件,但插件不是最新的。
我可以做這個沒有任何插件?我知道我可以如何做到這一點的頁面,但不適用於職位。
感謝您的幫助。
我有single.php文件,它爲我的帖子設置了默認模板。如何爲特定類別的帖子設置其他temlates/view?
如何爲特定類別的帖子設置更多視圖/模板?
我看到有插件,但插件不是最新的。
我可以做這個沒有任何插件?我知道我可以如何做到這一點的頁面,但不適用於職位。
感謝您的幫助。
很簡單。
看看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
}
試試這個,我希望這將是有益的。
您還可以通過修改您的查詢,並添加'category_name' => 'insertcategoryname',
來獲得某個類別的信息。