0

I don't want to define a template from admin because I have lot of page and so if I change it I might forget my selected template.

So I want make that template in page.

Here is my page structure

Mango (page)

-Orange (parent page)

-- lime (parent page)

For my mango and all parent pages I will use the same template, but I don't want to that by selecting one for each from admin. I want that defined in functions.php or page.php with get_template_part or any other way. For example, if lime/mango/orange or whatever which is under mango page, then get_template_part will use mango so that my template will be mango.php.

Any suggestions to make this work?

i am not sure is that make scene or not

0

All types of templates have filters to let you control what template is loaded. For pages there's page_template, where you can check the queried page against an ID, or see if the ID exists in an array of a page's ancestor IDs.

function wpd_page_template_filter( $template ){
    // the ID of Mango page
    $parent_page = 20;

    if( $parent_page == get_queried_object_id()
        || in_array( $parent_page, get_ancestors( get_queried_object_id(), 'page' ) ) ){
        $template = locate_template( 'mango.php', false );
    }
    return $template;
}
add_filter( 'page_template', 'wpd_page_template_filter' );
| improve this answer | |
  • yes this what i want.. it work. thanks .. thank you so much – Accore LTD Jun 5 '14 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.