How do I modify this page template to show subpage excerpts (not post excerpts)?

I have made a page template which shows linked subpages using this bit of code:

<?php
        $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'menu_order', 'sort_or

        foreach( $mypages as $page ) {
                $content = $page->post_content;
                if ( ! $content ) // Check for empty page
                        continue;

                $content = apply_filters( 'the_content', $content );
?>
        <h2><a href="https://wordpress.stackexchange.com/questions/69264/<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a><
        <div class="entry"><?php echo $content; ?></div>
<?php
}
?>

I got the code from here and have changed it to order subpages in the order of their Page Order.

It works, but it displays the full pages’ contents. I only want it to show page excerpts, with the featured image.

(I have enabled page excerpts in the editor by adding add_post_type_support( 'page', 'excerpt' ); to functions.php)

How do I modify this page template to show subpage excerpts?

2 Answers
2

Slightly modify these lines

$content = $page->post_content;
if ( ! $content ) // Check for empty page
    continue;

$content = apply_filters( 'the_content', $content );

to

$content = $page->post_excerpt;
if ( ! $content ) // Check for empty excerpt content & fallback to full content
    $content = $page->post_content;
if ( ! $content ) // Check for empty page
    continue;

$content = apply_filters( 'the_excerpt', $content );

UPDATE:
for adding featured image use

<div class="image"><?php echo get_the_post_thumbnail($page->ID);?></div>

Leave a Comment