CSS-Tricks*

A Web Design Community curated by Chris Coyier

A little dab'll do ya

Code Snippets

Code Snippets > WordPress > Embed a Page inside a Page Submit one!

Embed a Page inside a Page

<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?>
       <h3><?php the_title(); ?></h3>
       <?php the_content(); ?>
<?php endwhile; ?>

The above code can be used within the regular page loop. Replace **ID** with the ID of the page you wish to embed.

Subscribe to The Thread

  1. Kris says:

    instead of “page_id=”

    you could also use “pagename=”

  2. david says:

    ok,
    nice and thanks a lot for all this information.it is very very useful for me.i am fan but new in wordpress so i visit a lot your site.just one question.if i want to embed several pages inside a page,how can i do without repeating this same code several times?
    again thanks very cool informations ,actually i ve learned how to create my own theme because of you:)

  3. Cristobal says:

    Hi,

    Very good solution, I’ve been looking around for something like this a while and is good to find it in a few lines of code.

    It would be possible to show the content of the new page until the tag?

    thanks for the help.

  4. Cristobal says:

    the previous post I’ve fortot to add the “code” inside tags, I was talking about the “Read more” line that you can add to the article.

    Thanks

  5. Ant says:

    I am thinking to use that to parse one site content into one page (excessive pagination is bad!).

  6. Marc says:

    I know this is more about straight WP code/functions but I’m a huge fan of Improved Include Page – http://cl.ly/1X32

  7. Florian says:

    hmmmm somehow it doesnt work for me… :(

    im using wordpress 3.0 and my code looks correct for me, but even when i insert a post_id manually it won’t display anything… do you have any idea? I saved my code at a pastebin: http://pastebin.com/38GVT56j

    thank you very much…

  8. Florian says:

    ok, i got it on my own :)
    the problem only was that i used custom post types… so i had to tell the querry that it should enable displaying that specific posttype…


    $recent = new WP_Query(array( 'post_type' => 'seitenelemente', 'page_id' => 157 ));
    </code

  9. This works if your putting it at the very end of the loop, but if you want to continue working on the main loop afterwards, you’ll need to call

    wp_reset_query();

    Also keep in mind if using pagenames etc, it might be a good idea to specify that you only want a single post displaying using 'posts_per_page' => 1

  10. Hi!
    When I use this code:

    have_posts()) : $recent->the_post();?>

    All my recent comments (on the dashboard) – always have the exact page as their “In response to” => I wish I could send you some screenshots.

    So: “This is a comment” in response to “pagesidebar”, which doesn’t make sense and pretty confusing…(because ALL of the comments have the same in-reponse-to result)

    Does anyone here has same problem? HELP please?

It's Your Turn

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
--- The Management ---