I have created a hierarchical custom post type in wordpress called "films." It is hierarchical so it can have children elements.

When a "film" is clicked, wordpress automatically uses the template called 'single-films.php'. That is great, but I wish to use a different template when one of the film's children pages is clicked. For instance, a child of a film might be "press." When that film's press link is clicked, I want it to use a different template than single-films.php.

I was hoping there is some way I can use a template like single-children-films.php. Any ideas how I can change a hierarchical custom post type's children template?

  • or, another way of handling it is to add conditional logic to the single-films.php saying if this post is a parent, do this...if this post is a child, do this....But I'm unsure of the code to do that either.
    – JCHASE11
    Mar 18, 2012 at 16:39

1 Answer 1


If, from within single-films.php you filter based on the parent post you should have little issue with this. For example:

if( $post->post_parent != 0 ) {
    // not top level
} else {
    // top level page

If you need to know how deep the page is, that's a different matter, but that's also doable (unfortunately it means you need to query the database though).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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