不使用插件只需要一段簡潔的代碼就可以實(shí)現(xiàn),WordPress子頁面自動(dòng)調(diào)用父頁面的模板。
function wodepress_use_parent_template() {
global $post;
$curr_tmp = get_post_meta($post->ID, '_wp_page_template', true); //獲取頁面模板
if($post->post_parent){
$parent_tmp = get_post_meta($post->post_parent, '_wp_page_template', true); //如果有父頁面,獲取父頁面模板
update_post_meta($post->ID, '_wp_page_template', $parent_tmp, $curr_tmp); //設(shè)置子頁面的模板為父頁面的模板
}
}
add_action('save_post','wodepress_use_parent_template');
將上面這段代碼加到functions.php文件中,就可以以非插件的方法實(shí)現(xiàn),非常簡單實(shí)用。