Ready to get started?Download WordPress


[resolved] How to embed a page into the main index? (10 posts)

  1. Vadi
    Posted 6 years ago #


    I'd like to embed a wordpess page into the main index page of wordpress, such that the page appears first and then the latest posts appear after it. I found the command for embedding a page to be <?php query_posts('pagename=about');?></div> (with the "about" page being the one I want to embed). However no matter what I try, if I get the embedded page to show, then none of the posts will show.

    Can anyone help out please? Where is the proper place to add the code to?

  2. educationthemes
    Posted 6 years ago #

    Try this above the posts code (outside the loop)

    <?php $recent = new WP_Query("page_id=2"); while($recent->have_posts()) : $recent->the_post();?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    <?php endwhile; ?>

    This will show the page with ID 2. Change this number 2 to whatever page you want to display.

  3. Vadi
    Posted 6 years ago #

    Great, thanks! It worked perfectly (http://mudlet.org/)

  4. Vadi
    Posted 6 years ago #

    Sorry to bother again, but while this works in a template, it doesn't work as html in a page.

    The php code gets cutoff and shown half-way... any way to fix that? I already disabled the visual editor.

  5. moshu
    Posted 6 years ago #

    PHP is not executed on a html file.

  6. Vadi
    Posted 6 years ago #

    I see. Just literally copying the page contents is the only way to "embed" a page?

  7. moshu
    Posted 6 years ago #

    Let's get back to the basics.

    What do you call "a page"?

    Furthermore, any PHP code is executed ONLY in templates, never in the content of a post or Page (aka when writing a post or Page in the WP admin panel). Nobody ever said that it would happen.

    You said you wanted to include/embed a page (Page?) into your main index. index = a template file. You got the solution.

    So, I don't understand what is the issue now.

  8. Vadi
    Posted 6 years ago #

    Ah sorry. Now my case changed, I'd like to embed a page inside another page.

    I have several pages that are children of a page, such that they appear as links in the sidebar. However, I'd like to have all of them in the parent page also.

  9. moshu
    Posted 6 years ago #

    For that (i.e. showing subPages on a parent Page) there should be some custom code. Try to search. And always read the docs before posting:
    (and use capital P for Pages so we know you know what you are talking about)

    If you change your mind again - here is a plugin for posts and Pages alike: http://guff.szub.net/2005/01/27/get-a-post/

  10. luclatulippe
    Posted 5 years ago #

    This was exactly the solution I was looking for, so thanks a million!

Topic Closed

This topic has been closed to new replies.

About this Topic