Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Displaying Page Data From About Page Page on Static Home Page Wordpress?

Hi everyone!

I'm on with a little project just seeing what I've learned and what is possible and I would like to have an excerpt of my about page displayed on my home page.....

From my research of the web I have this below:

    <section class="container">

        <div class="row">

            <div class="col-md-6">


                    $page_id = 11;
                    $page_data = get_page( $page_id );
                    $content = $page_data->post_content;
                    $title = $page_data->post_title;


                <h2><?php echo $title ?></h2>
                <p><?php echo $content ?></p>




I works but its the full page content for obvious reasons but I cant figure out how to get and excerpt of that content!

Also is this the best way to achieve this ?

Thanks people!


2 Answers

Sue Dough
Sue Dough
35,800 Points

Why would the except show? You never did anything with the excerpt.

Start here. https://codex.wordpress.org/Function_Reference/the_excerpt

Sorry I must have jumbled up my question, I know the excerpt wont show not with the code above. I am wanting to replace the code used to get the content with the necessary code for getting the excerpt.

I have had a number of failed attempts so far and wasn't sure if what i was doing was the best way either :)

Sue Dough
Sue Dough
35,800 Points

Okay well erase it all and try this. Make sure the page is named about.

     $page = get_page_by_title( 'About' );
     $the_excerpt = $page->post_excerpt;

Thanks, Does this need to be in a loop / Query?

Sue Dough
Sue Dough
35,800 Points

No I don't think so.

I ended up with this in the end, I could not get post_excerpt to work correctly...

            <!-- Custom Query Column to Loop About Us Page -->
            <div class="col-md-6"> 

                <!-- Custom Query args -->

                    $args = array(

                            //Declare page as post type
                            'post_type' => 'page',
                            //Declare page ID
                            'page_id'   => '11'


                    //Declare variable as your new query data
                    $page_query = new WP_Query($args);


                <!-- Open Custom Query Loop -->
                <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>


                        <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>

                        <p><?php the_excerpt(); ?></p>


                <?php endwhile; ?> 
                <!-- //Close Custom Query Loop -->      

            <!-- //Close Custom Query Column -->

Thanks for all your advice :)