WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to display child page from specific parent page in homepage ?

This is my page structure

About Us
Hotel Category
  Hotel A
    Room 1
    Room 2
  Hotel B
    Room 1
    Room 2
  Hotel C
    Room 1
    Room 2
Contact Us

And i try to achieve this at homepage(parent page is Hotel Category : id=8)

Hotel A
Hotel B
Hotel C

List Hotel A, Hotel B and Hotel C with some except and thumbnail image(this magic field)

share|improve this question

migrated from stackoverflow.com Apr 20 '12 at 14:10

This question came from our site for professional and enthusiast programmers.

Try this plugin. You can use it in your sidebar(as widget) and set which posts you want to show. – Przemysław Mirota Apr 20 '12 at 14:13

Below code (Template for show child pages with title and excerpt) might useful to you. if you are using wordpress category->post instead of worpdress page, change the wp_query accordingly. You can get more information about wp_query : http://codex.wordpress.org/Class_Reference/WP_Query

Here's the template code:

<?php /** Template Name: show child pages */ get_header(); ?> <div id="container"> <div id="content" role="main"> <?php get_template_part( 'loop', 'page' ); global $post; $args=array( "post_parent" => $post->ID, 'paged' => get_query_var( 'page' ), 'post_type' => 'page' ); // The Query $the_query = new WP_Query( $args ); // The Loop echo "<ul>"; while ( $the_query->have_posts() ) : $the_query->the_post(); echo '<li class="chiled-title">'; the_title(); the_excerpt(); echo '</li>'; endwhile; echo "<ul/>"; ?> <?php if ( $wp_query->max_num_pages > 1 ) : ?> <div id="nav-below" class="navigation"> <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div> <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div> </div><!-- #nav-below --> <?php endif; ?> <?php // Reset Post Data wp_reset_postdata(); ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>
share|improve this answer

This should do it.

  $pages = get_pages('child_of=199');
  foreach($pages as $child) {
  <h3><?php echo get_the_title($child->ID); ?></h3> 
  // This next line gets the full page of content
  // echo get_post_field('post_content', $child->ID);

 // This next line will cut the content off at 450 letters
  // With a read more link under it 
  echo '<p>' . substr(get_post_field('post_content', $child->ID), 0, 450) . '</p>'; ?> 
 <a href="<?php echo get_permalink( $child->ID ); ?>"> READ MORE </a> 
<?php } ?>

Change "child_of=199" with the ID of the page you want to get the children of.

There is a line that is commented out, that line will get the full page of content

The line that is being used to get content will only get the first 450 letters.

There has to be a better way to get content, as this pulls in the HTML and all - so if that first 450 letter happens to land in the middle of a image you will have broken text.

I am sure a quick google search of "get post content by Id" should help with that part

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.