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 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="<?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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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>
share|improve this answer
    
Excellent. Thank you very much. –  paradroid Oct 15 '12 at 12:26
add comment

A reworked example of your snippet

This sample shows you how you can make use of plugins that hook their actions into filters or hooks. It also allows to use password protection for the child post incl. default core translation strings.

$wpse69264_child_pages = get_pages( array(
     'child_of'    => in_the_loop ? get_the_ID() : $post->ID // Are we in the loop?
    ,'sort_column' => 'menu_order'
    ,'sort_order'  => DESC
) );

foreach ( $wpse69264_child_pages as $child )
{
    // Default filters: Excerpt length - Also takes languages in account where 1 char = 1 word (like Chinese)
    $output = $child->post_excerpt ? $child->post_excerpt : apply_filters( 'excerpt_length', $child->post_content );

    if ( post_password_required( $child ) )
    {
        // Default translation
        _e( 'There is no excerpt because this is a protected post.' );
        continue;
    }

    // Just in case    
    $output = force_balance_tags( $output );

    // Default filters:
    $output = apply_filters( 'get_the_excerpt', $output );
    echo apply_filters( 'the_excerpt', $output );
}
unset( $wpse69264_child_pages, $child );
share|improve this answer
    
Thanks. That may be useful once I get to the point where I know what you're on about. –  paradroid Oct 15 '12 at 15:38
add comment

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.