• Resolved exex5123

    (@exex5123)


    Hi!

    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:

    <?php
    $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; ?>">
    		<?php
    		$content = $page->post_content;
    		$content = apply_filters('the_content', $content);
    		$content = str_replace(']]>', ']]>', $content);
    		echo $content;
    		?>
    
    	</div>

    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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter exex5123

    (@exex5123)

    Got it!

    This is my solution:

    content-children.php

    <?php
    /**
     * @since XXXXX
     */
    ?>
    
    <?php
    
    $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 -->
    
    			<?php
    			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>
                </div>
    
            </article>
    
        <?php endwhile; ?>
    
    <?php endif; wp_reset_query(); ?>

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

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

    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show Child Pages with excerpts and "Read more"’ is closed to new replies.