WordPress — 用程式客製化特定文章的佈景主題
2 min readAug 29, 2019
把下面的code貼到function.php中,然後在佈景主題的資料夾裡面,找到一個single.php的檔案,這個檔案就是文章的模版,複製一份,並將檔案改成single-{文章ID}.php就可以了。
至於文章ID(Post ID)要怎麼看,你可以進入你的文章編輯頁面,這個頁面的網址中可以看到文章ID。舉例來說,我這篇文章的編輯網址如下,其中post = 123456就是我的文章ID。
https://aronhack.com/wp-admin/post.php?post=123456&action=editadd_filter( 'single_template', 'check_post_custom_template');
function check_post_custom_template($template){
global $post;
$custom_template = locate_template( "single-{$post->ID}.php" );
if ( ! empty( $custom_template ) ) {
$template = $custom_template;
}
return $template;
}