1

I've never thought to do this with WordPress until now, but I was wondering is it possible for two templates to be chosen to create a post or page in WordPress?

When you are on the 'Edit Page' there is the 'Page Attributes>Template' section. When a custom template is chosen that will generate the main layout of the page which includes the region for an iframe. The iframe comes into play when the custom-field below the content editor is filled out, which would automatically call the second custom template when the page is published.

So basically, for the sake of a visual, imagine a comparison site with side-by-side view of two pages. Only now think of that example as a side-by-side view of data inputted into the_content (WP content editor) and custom_field (custom field box/field below the WP content editor).

The iframe is needed, but if you know what other code could be used to produce the same results would be fine.

  • When you write about "side-by-side view of data", you want one side with the main content of the post and the other side with the content of a custom field ? – mmm Dec 30 '17 at 19:57
  • Yes, and with the content of the custom field and its own custom template being iframed, if possible. – Bari Dec 31 '17 at 1:07
  • not possible by default but can be implemented. you can also consider using template parts with corresponding templates that include them. and when building this kind of page, just include the template part for the selected template in a div. – inarilo Dec 31 '17 at 3:30
0

No, you would not use two page-templates on a single page.

Yes, you can have a different admin-page layout / configuration for different page-templates.

Page-template-A could have two post-editors and page-template-B (or post-format for that matter) could have only a name, email, and featured-image.

You could use a single page template and separate includes to help organize your code.

<?php
// Template Name: 289812
?>
<div class="page-tpl-289812">
    <?php get_template_part( 'filename_foo' ); ?>
    <?php get_template_part( 'filename_bar' ); ?>
</div>

Add filename_foo and filename_bar to your theme. filename_foo outputs one editor-section and filename_bar outputs the other.

There are many ways to add additional custom input to the admin-side of anything in WordPress which I won't discuss here.

0

The way I would approach this is to use template parts and call them up based on the value of the meta field. For example:

<?php
   // Standard Template Statements

   $template_part = // Get Custom Meta Value
   get_template_part( 'template-parts/content-split', $template_part );

?>

So say the meta value is "blue", then WordPress will look for {theme}/template-parts/content-split-blue.php and include it there.

You may want to set it up as a series of if/then/elseif checks though so there is a fallback template part to use instead.

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.