Ready to get started?Download WordPress


[resolved] Show Child Pages with excerpts and "Read more" (5 posts)

  1. exex5123
    Posted 1 year ago #


    I have a page on which I want to show only it's child pages' excerpts. Underneath these excerpts there should be a "read more" button. I want to achieve this by adding the <---more---> quicktag in the pages.

    This is what I have:

    $pages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ));
    $pagecount = count($pages); ?>
    <?php foreach($pages as $page) { ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class($column); ?>>
    	<header class="entry-header">
    		<h4 class="entry-title"><?php echo $page->post_title ?></h4>
    	</header><!-- .entry-header -->
    	<div class="front-page entry-content" id="<?php echo $page->post_name; ?>">
    		$content = $page->post_content;
    		$content = apply_filters('the_content', $content);
    		$content = str_replace(']]>', ']]>', $content);
    		echo $content;

    However I don't get it to show any excerpts! Setting the quicktag doesn't seem to have any influence and I'm also missing the "read more" links!

    How do I get that?

    Thank you so much!

  2. exex5123
    Posted 1 year ago #

    Got it!

    This is my solution:


     * @since XXXXX
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => $post->ID,
        'order'          => 'ASC',
        'orderby'        => 'menu_order'
    $parent = new WP_Query( $args );
    if ( $parent->have_posts() ) : ?>
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class($column); ?>>
    		<header class="entry-header">
    			<h4 class="entry-title"><?php the_title(); ?></h4>
    		</header><!-- .entry-header -->
    			global $more;
    			$more = 0;
                <div class="front-page entry-content" id="<?php echo $page->post_name; ?>">
                <?php the_content('<p style="text-align:right">> read more</p>'); ?></p>
        <?php endwhile; ?>
    <?php endif; wp_reset_query(); ?>
  3. Andrea Reed
    Posted 8 months ago #

    That's awesome! How do you display this in a page? Thanks!

  4. Maurice van Opdorp
    Posted 7 months ago #

    Probably with include:
    <?php include("content-children.php"); ?>

  5. yesmaybe
    Posted 5 months ago #

    and where would you put this code?

    I presume it is saved directly under \wp-admin?

    And how do you call it on a particular page, but not all pages?

    Does this use the featured image and then an excerpt? How do you decide how many excerpts are presented on a page?

    Thanks for your support? This seems like something I could really use, is it made into a plugin by now?

Topic Closed

This topic has been closed to new replies.

About this Topic