$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' AND post_status = 'publish' ORDER BY menu_order ASC", 'OBJECT');
                if ( $child_pages ) {
                    foreach ( $child_pages as $pageChild ) {
                        setup_postdata( $pageChild );
                        $thumbnail = get_the_post_thumbnail($pageChild->ID, 'thumbnail');
                        //var_dump($thumbnail);
                        //if($thumbnail == "") continue; // Skip pages without a thumbnail
                        
                        if ($thumbnail == "") {
                                // Extract the thumbnail from the first attached imaged
                                $allimages =&get_children('post_type=attachment&post_mime_type=image&post_parent=' . $pageChild->ID );
                                if ($allimages){
                                    foreach ($allimages as $img){
                                            $attachId = $img->ID;
                                            $img = wp_get_attachment_image_src( $attachId, array(150,150));
                                            $thumbnail = " ";
                                    }
                                } else {
                                    $src = get_site_url().'/wp-content/uploads/2015/10/thumbnail-default1.jpg';
                                    $pattern = '@.*)".*>@Uims';
                                    $str     = $subpageChild->post_content;
                                    preg_match($pattern, $str, $matches);
                                    if( !empty($matches) ) {
                                        $src = $matches['SRC'];
                                        
                                    }
                                    $thumbnail = "
";
                                    }
                                } else {
                                    $src = get_site_url().'/wp-content/uploads/2015/10/thumbnail-default1.jpg';
                                    $pattern = '@.*)".*>@Uims';
                                    $str     = $subpageChild->post_content;
                                    preg_match($pattern, $str, $matches);
                                    if( !empty($matches) ) {
                                        $src = $matches['SRC'];
                                        
                                    }
                                    $thumbnail = " ";
                                }
                        }
                        
                    //We check if there is any grandchildren pages
                    $childId = $pageChild->ID;
                    $subchild_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$childId." AND post_type = 'page' AND post_status = 'publish' ORDER BY menu_order ASC", 'OBJECT');
                        
                ?>
";
                                }
                        }
                        
                    //We check if there is any grandchildren pages
                    $childId = $pageChild->ID;
                    $subchild_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$childId." AND post_type = 'page' AND post_status = 'publish' ORDER BY menu_order ASC", 'OBJECT');
                        
                ?>
                        - 
                          
                               if (!$subchild_pages) { ?>
                                
                                                                     } ?>
                                                                   if ( $subchild_pages ) {
                    ?>
                            
                    
                    foreach ( $subchild_pages as $subpageChild ) {
                        setup_postdata( $subpageChild );
                        $thumbnail = get_the_post_thumbnail($subpageChild->ID, 'thumbnail');
                        
                        if ($thumbnail == "") {
                                // Extract the thumbnail from the first attached imaged
                                $allimages =&get_children('post_type=attachment&post_mime_type=image&post_parent=' . $subpageChild->ID );
                                if ($allimages){
                                    foreach ($allimages as $img){
                                            $attachId = $img->ID;
                                            $img = wp_get_attachment_image_src( $attachId, array(150,150));
                                            $thumbnail = " ";
                                            //break;
                                    }
                                } else {
                                    $src = get_site_url().'/wp-content/uploads/2015/10/thumbnail-default1.jpg';
                                    $pattern = '@.*)".*>@Uims';
                                    $str     = $subpageChild->post_content;
                                    preg_match($pattern, $str, $matches);
                                    if( !empty($matches) ) {
                                        $src = $matches['SRC'];
                                        
                                    }
                                    $thumbnail = " ";
                                            //break;
                                    }
                                } else {
                                    $src = get_site_url().'/wp-content/uploads/2015/10/thumbnail-default1.jpg';
                                    $pattern = '@.*)".*>@Uims';
                                    $str     = $subpageChild->post_content;
                                    preg_match($pattern, $str, $matches);
                                    if( !empty($matches) ) {
                                        $src = $matches['SRC'];
                                        
                                    }
                                    $thumbnail = " ";
                                }
                        }
                ?> ";
                                }
                        }
                ?>
- 
                          
                                
                                                                     
                                                                   
} //end inner foreach
                    ?> 
} //end foreach
                    }
                }
                ?> 
		 
						
	
			
			
				
					
		 
		
		 
 
 
 
Scroll to top