Posted By

hussong on 06/30/15


Tagged

template wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Shoora


WordPress Parent Page with Child Page Excerpts


 / Published in: PHP
 

Snippet for a parent page to list child pages with excerpts.

  1. <div class="entry-content entry">
  2.  
  3. <?php the_content(); ?>
  4.  
  5. </div><!-- .entry-content -->
  6.  
  7. <!-- list child-pages with links and excerpt -->
  8. <?php global $post; ?>
  9. <?php $pages = get_pages( array( 'child_of' => $post->ID, 'orderby' => 'menu_order' ) ); ?>
  10. <?php if ( $pages ) : ?>
  11. <?php $inner_query = new WP_Query("post_type=page&posts_per_page=-1&post_parent={$id}&orderby=menu_order&order=ASC");
  12. while ($inner_query->have_posts()) : $inner_query->the_post(); ?>
  13. <h2 class="children-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  14. <?php the_excerpt(); ?>
  15.  
  16. <?php endwhile; endif; ?>
  17.  
  18. <?php wp_reset_query(); ?>

Report this snippet  

You need to login to post a comment.