WordPress - Display Child Pages w/ Thumbnails


/ Published in: PHP
Save to your folder(s)

Takes the ID of a page, then displays a list of child pages with thumbnails and page titles. The thumbnail is generated from the 'featured image' of the particular child page.


Copy this code and paste it in your HTML
  1. <?php
  2. //get current page ID
  3. $the_id = '14';
  4.  
  5. $args = array(
  6. 'child_of' => $the_id,
  7. 'title_li' => '',
  8. 'parent' => $the_id,
  9. 'sort_order' => 'DESC',
  10. 'sort_column' => 'menu_order'
  11. );
  12.  
  13. $pages = get_pages( $args );
  14.  
  15. $output = '';
  16.  
  17. foreach($pages as $value){
  18.  
  19. $thumb = get_the_post_thumbnail( $value->ID, array(230,299), $attr = 'class=shopthumbnail' );
  20. $output .= "<li>";
  21. $output .= "<a href='" . $value->post_name . "' >" . $thumb . "</a><br />";
  22. $output .= "<a href='" . $value->post_name . "' >" . $value->post_title . "</a>";
  23. $output .= "</li>";
  24. }
  25.  
  26. echo $output;
  27. ?>
  28.  
  29. </ul>

Report this snippet


Comments


You need to login to view comments.