Get content from one page and show it on another page

So, I’ve been googling and reading and testing and failing.

I’m fairly new to php, so don’t expect to much 🙂

Read More

I’m working on a new design, and I want to show content from the about page on my homepage, which is dynamic. So, I’ve been looking into that the_content thing, but I havent gotten any luck so far.

<?php
   $id=about;
   $post = get_page($id=);
   $content = apply_filters('the_content', $post->post_content);
   echo $content;
?>

the ID of the page is “about”, if that is any help.

Please get back to me 🙂

Related posts

Leave a Reply

4 comments

  1. First off: The ID of a post or page is always an integer. “about” is either your about page’s title, slug or both.

    Including the following in your “homepage’s” page template or in the sidebar combined with conditional tag(s) will display the about page’s content:

    <?php
        // query for the about page
        $your_query = new WP_Query( 'pagename=about' );
        // "loop" through query (even though it's just one page) 
        while ( $your_query->have_posts() ) : $your_query->the_post();
            the_content();
        endwhile;
        // reset post data (important!)
        wp_reset_postdata();
    ?>
    

    Edit: The above works, IFF your page’s slug is indeed “about”, otherwise adjust accordingly.

  2. I wanted something similar but with page Title, this is how I achieved it:

    $args = array(
        'post_type' => 'page',
        'title' => 'The title of the page you want'
    );
    
    $your_query = new WP_Query( $args );
    while ( $your_query->have_posts() ) : $your_query->the_post();
        the_content();
    endwhile;
    
  3. Best way to get the current page content

    global $post;
    echo $post->post_content;
    

    or

    global $wp_query;
    echo $wp_query->post->post_content;