WordPress Snippets at WPcustoms

Dynamically use parent template for child pages

If you use a specific template for a parent page this function automatically uses this template for the page’s child pages. No manual updating required. The code checks the page template meta field when you save a post and if it has a parent page it uses the page template from that one.

 * Snippet Name: Dynamically use parent template for child pages
 * Snippet URL: http://www.wpcustoms.net/snippets/dynamically-use-parent-template-for-child-pages/
 function wpc_use_parent_template(){
    global $post;
    $curr_tmp = get_post_meta($post->ID, '_wp_page_template', true);
        $parent_tmp = get_post_meta($post->post_parent, '_wp_page_template', true);