Get the_excerpt of a child page from within a parent page
-
Having trouble getting the excerpt of a child page from within a parent page. I have a static parent page, that within, lists excerpts of all child pages that are hierarchal of that parent.
For some reason I can return each title and publish date of each individual child page. But when I try to echo get_the_excerpt or the_excerpt all I get is the excerpt or content of the parent-page for every child page listed. Also I’m converting the standard excerpt into a custom trimmed excerpt. This worked on the “front-page” but not in a standard “parent-page”.
Not sure what I’m doing wrong or overlooking.
This is what appears… note: “The parent page content” repetition.
Parent Page Title
The parent page contentTest Child Page Title A
The parent page content<
Nov 16, 2016Test Child Page Title B
The parent page content
Oct 5, 2016Using this solution:
<?php // Begin listing all child pages $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) ); foreach( $mypages as $page ) { ?> <div class="paged-entries"> <div class="entry"> <h3 class="page-headline"><?php echo $page->post_title; ?></h3> <!-- .entry-summary --> <div class="post-excerpt"> <?php $content = get_extended( $page->post_content ); $page_excerpt = wpse0001_custom_wp_trim_excerpt($content); echo $content['main']; ?> </div> <!-- end .entry-summary --> <h6>Published: <?php echo date("M Y", strtotime($pfx_date = get_the_date( $format, $page->ID ))); // d m y ?></h6> </div> </div> <?php } ?>
This is what I’m after:
Parent Page Title
The parent page contentTest Child Page Title A
The child page excerpt A
Nov 16, 2016Test Child Page Title B
The child page excerpt B
Oct 5, 2016- This topic was modified 8 years ago by . Reason: Formatting
- This topic was modified 8 years ago by . Reason: Formatting
- This topic was modified 8 years ago by .
- This topic was modified 8 years ago by . Reason: Formatting and better detail
- The topic ‘Get the_excerpt of a child page from within a parent page’ is closed to new replies.