1

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.

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

2
  • There are a number of related questions to the right under "Related". Do none of those help?
    – s_ha_dum
    Jun 11 '13 at 21:34
  • Some of these are useful, but i'm still in need to post the thumbnails with permalinks of child pages, when even on other child pages from the same parent page?
    – David
    Jun 11 '13 at 21:41
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>';
    }
  }
}
3
  • how do I link the thumbnails to their permalink pages?
    – David
    Jun 11 '13 at 22:28
  • @David : see the edit
    – s_ha_dum
    Jun 11 '13 at 22:37
  • without specifying posts_per_page => -1 you will be limited to only the number that is set in admin. (usually 10) Also this seems it would only work on child pages, but not on the parent page.
    – jave.web
    Feb 9 at 1:38
0

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-->
1
  • I have 2 worries about this - doesn't the meta_key argument limit the pages to only ones with actually having the thumbnail? Wouldn't a fallback thumbnail image be more generic solution? Also without specifying posts_per_page => -1, you'd be only limited to the number of posts set in admin.
    – jave.web
    Feb 9 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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