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.

I inserted an excerpt into a Page using the "More" button in WP GUI.

I have a custom loop-page.php from which I want to display the excerpt. But it appears to be empty?

Is it possible to display excerpts from child pages?

$pageChildren = get_pages('sort_column=menu_order&hierarchical=0&child_of='.$post->ID);
if ( $pageChildren ) {
  foreach ( $pageChildren as $pageChild ) {
    echo '<p>And the title is: '. $pageChild->post_title.'</p>';
        print_r($pageChild);
        if (!empty($pageChild->post_excerpt)){
            echo '<p><a href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_excerpt.'</a> </p> ';
        }
        echo '<hr />';
  }
}

enter image description here

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Using the "more" tag does not create an excerpt. It simply creates a "Read More" link when displaying the_content() on index pages.

Excerpts are created/displayed as follows:

To display an excerpt, your template file needs to call "the_excerpt()" rather than "the_content()". Note: you use the equivalent $post->post_excerpt, which should also work just fine.

The "the_excerpt()" template tag then displays the excerpt, which is created as follows:

1) By entering excerpt content into the "Excerpt" field on the Edit Post/Edit Page screen. 2) Automatically, based on number of characters, if no content is added to the "Excerpt" field.

EDIT:

Okay so I totally missed this at first. Only Posts have the "excerpt" field. Pages don't have the "excerpt" field. So, $post->post_excerpt will never be populated for Pages (I think).

Try running "setup_postdata( $pageChild )" inside your foreach loop, and then replacing "$pageChild->post_excerpt" with "get_the_excerpt()":

foreach ( $pageChildren as $pageChild ) {
    setup_postdata( $pageChild );
    echo '<p>And the title is: '. $pageChild->post_title.'</p>';
        print_r($pageChild);
            echo '<p><a href="' . get_permalink($pageChild->ID) . '">' . get_the_excerpt() .'</a> </p> ';
        echo '<hr />';
}

Does that work?

share|improve this answer
    
Hi Chip. I understand excerpts now, but I can't find where they are entered. I added a screenshot of what I see when editing a post. There doesn't appear to be an "excerpt" area. This is why I thought 'more' was 'excerpt' –  mrtsherman Mar 28 '11 at 18:41
    
I don't see the screenshot, but I suspect the issue is that the "Excerpt" field isn't enabled. From your Post Edit screen, click the "Screen Options" tab in the upper right-hand corner, and ensure that the checkbox for "Excerpt" is enabled (checked). –  Chip Bennett Mar 28 '11 at 18:44
    
I guess my theme doesn't have excerpt built in. When I click screen options there is no checkbox or area for excerpt. –  mrtsherman Mar 28 '11 at 19:06
    
My mistake. Pages don't have $post->post_excerpt. I updated my answer with another suggested fix. –  Chip Bennett Mar 28 '11 at 19:15
4  
You can add excerpts to Pages like this (call this on init): add_post_type_support( 'page', 'excerpt' ); –  goldenapples Mar 28 '11 at 20:05
show 2 more comments

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.