SkyNetworks
SkyNetworks

Reputation: 45

Page Excerpt in WordPress

Not sure if anyone can help please, but I'm having problems displaying the excerpts for Pages on my WordPress site. I've already looked at this page (How to display page excerpt in Wordpress) but still can't get it to work. Here's the code I'm using:

    <?php
    $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'meta_value' => 'C4News', 'sort_order' => 'desc' ) );
    foreach( $mypages as $page ) {
    $content = $page->post_content;
    if ( ! $content ) // Check for empty page
    continue;
    $content = apply_filters( 'the_content', $content );
    ?>
    <div class="page-excerpt-panel">
    <a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo get_the_post_thumbnail( $page->ID, 'thumbnail', array('class' => 'page-listing-thumbnail')); ?></a>
    <span class="page-excerpt-text-panel"><span class="post-excerpt-title"><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></span><?php the_excerpt();?></span>
    </div>
    <?php
    }
    ?>

I've already added two bits of code to my functions.php file - (1) to enable manual excerpts for Pages, and (2) to use a customised 'Read More' link at the end of excerpts. Everything works fine on the blog index page (which displays the post thumbnail, title, manual excerpt and customised 'Read More' link), but when I've tried to replicate the same thing for a list of Pages using the above code, it only shows the thumbnail, title and 'Read More' link (with no excerpt).

The problem can be seen here: http://www.retelevise.com/televisionnews/

And yet it works fine for Posts on the blog index page here: http://www.retelevise.com/blog/

Any ideas what I'm doing wrong please? Thanks.

Upvotes: 0

Views: 814

Answers (2)

SkyNetworks
SkyNetworks

Reputation: 45

Ok, I think I've done it (after reading the answer posted here: https://wordpress.stackexchange.com/questions/60304/get-page-title-url-and-excerpt-of-a-page). I ended up calling the excerpt with:

    <?php echo $page->post_excerpt; ?>

instead of just

    <?php the_excerpt(); ?>

For some reason it only picks up the excerpt if I've inputted a manual one, but I think that's fine. I just need to get into the habit of doing that. I still can't get it to show the 'Read More' link though, but thanks everybody.

Upvotes: 0

Devin
Devin

Reputation: 7720

You only need to add this to functions.php

add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
     add_post_type_support( 'page', 'excerpt' );
}

and then call the_excerpt like in any post or category. That's all what you need, don't over complicate things

Upvotes: 3

Related Questions