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 />';
}
}
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()”:
Does that work?