Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 '12 at 16:39
add comment

1 Answer 1

up vote 0 down vote accepted

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).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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