Display child pages on a parent and child page using Featured Thumbnails

How would I display a list of my child pages using featured images on a its parent page as well as its other siblings child page?

For example, if my parent page is called ‘Music’, I’ll have my main content with child pages thumbnails at the bottom.

Read More

I’d like to have thumbnails with permalinks to other child pages from within the parent Music page displayed across all of the child music pages.

Is this possible?

Thanks

Related posts

2 comments

  1. Use get_ancestors to get the page parent, then get the children of that parent.

    $ancestors = array();
    $ancestors = get_ancestors($post->ID,'page');
    $parent = (!empty($ancestors)) ? array_pop($ancestors) : $post->ID;
    if (!empty($parent)) {
      $kids = new WP_Query(
        array(
          'post_parent'=>$parent,
          'post_type' => 'page',
          'ignore_sticky_posts' => true
        )
      );
      if ($kids->have_posts()) {
        while ($kids->have_posts()) {
          $kids->the_post();
          echo '<a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_post_thumbnail().'</a>';
        }
      }
    }
    
  2. This is the best solution worked so far for me, which is combination of multiple solutions i found online,

    With this code you can display Sub Page Featured Image and Title with anchor link.

    Also this work for Sub and Child page too.

    <!--Child Page Thumbnails Start-->
    <?php 
      $subs = new WP_Query( 
        array( 
          'post_parent' => $post->ID, 
          'post_type' => 'page', 
          'meta_key' => '_thumbnail_id' 
        )
      );
    if( $subs->have_posts() ) : 
      while( $subs->have_posts() ) : 
        $subs->the_post();
        echo '<article class="span_8 col clr-margin products-thumb"> <a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_post_thumbnail().'</a>'.'<br/><h2><a href="'.get_permalink().'">'.get_the_title().'</a></h2></article>';
      endwhile; 
    endif; 
    wp_reset_postdata(); ?>
    <!--Child Page Thumbnails End-->
    

Comments are closed.