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 there a way to include a wordpress Page into another one? I'm not just talking about getting the content using get_page(), but to import the whole page (theme + content). I have been looking around for hours for a way to achieve this but I can't find a way, I guess it's a pretty unusual thing to try to do, but it's necessary for what I want to do with my site.

What I want to achieve is this:

Page1 uses this template:

<?php
/*
Template Name: page-template1
*/
?>

<div id="content">
 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
 <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
 <div class="entrytext">
  <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
 </div>
 </div>
 <?php endwhile; endif; ?>
</div>

<div>
Hello
import_page("page2");
</div>

Page2 uses this template:

<?php
/*
Template Name: page-template2
*/
?>

<div>
World

<div id="content">
 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
 <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
 <div class="entrytext">
  <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
 </div>
 </div>
 <?php endwhile; endif; ?>
</div>

</div>

Result:

<div>
World

<div id="content">
 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
 <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
 <div class="entrytext">
  <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
 </div>
 </div>
 <?php endwhile; endif; ?>
</div>

</div>
<div>
Hello
<div>
World

<div id="content">
 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
 <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
 <div class="entrytext">
  <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
 </div>
 </div>
 <?php endwhile; endif; ?>
</div>

</div>
</div>
share|improve this question
    
Maybe an explanation of why you want to do this would help? What is the point, in human terms? –  s_ha_dum Jan 21 '13 at 15:28
    
Also, I notice that your title states "add static html". You aren't trying to add static HTML. You are adding dynamic-- PHP generated-- HTML. Can you explain the discrepancy? –  s_ha_dum Jan 21 '13 at 15:30
add comment

1 Answer 1

You can use locate_template().

locate_template( 'page-template2', true );
share|improve this answer
    
But I wouldn't get the contents of the page then, only the template, right? –  Lukas K Jan 21 '13 at 14:54
    
Take a look at the source. This requires and loads the file. Just try it. –  kaiser Jan 21 '13 at 14:58
1  
@LukasK, You may not get the results you want though. Unless your second template has its own query-- looks like it doesn't-- it will try to Loop through the same query results used by template1 and that query hasn't been reset. –  s_ha_dum Jan 21 '13 at 15:27
    
@s_ha_dum Double that. But hard to keep track with a constantly evolving question :P –  kaiser Jan 21 '13 at 15:29
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.