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.

Is it possible to enable a second content area in the edit screen if a certain template is chosen?

I have seen plugins like the second section plugin but that enables it for all pages I would like to only have the second section if a certain page template is chosen for a page.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You could add a metabox for your second content section, then hide it with a bit of javascript if the current template isn't a specific template:

current_template = jQuery('#page_template').val();
if( current_template != 'my-special-template.php' ){
    jQuery('#_your_meta_box_id').hide();
}

then bind a function to the change event of the template dropdown and show it when a specific template is selected:

jQuery('#page_template').change(function(){
    selected_template = jQuery(this).val();
    if( selected_template == 'my-special-template.php' ){
        jQuery('#_your_meta_box_id').show();
    }
});
share|improve this answer
    
Thanks that is a nice idea, my only concern would be users without JavaScript on. –  Lee Sep 9 '11 at 8:05
    
@Lee - without javascript the only way to do it would be to require that they select a template then save the post before they're able to see the additional content section. the visual editor doesn't work and there's no way to add images to a post without js anyway. –  Milo Sep 9 '11 at 14:46
    
|Good point I will try it out and see how I get on - thanks :) –  Lee Sep 9 '11 at 15:38

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.