To get all the “root” pages of a site:
$args = array(
'post_type' => 'page',
'child_of' => 0,
);
$pages = get_pages( $args );
foreach( $pages as $page ) {
if( has_post_thumbnail( $page->ID ) {
$imgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
$imgwidth = $imgdata[1]; // thumbnail's width
$imgheight = $imgdata[2]; // thumbnail's height
}
}
// handle the image as in your posted code
To get your custom post type, you should be able to replace 'post_type' => 'page'
with your CPT’s name (eg, 'post_type' => 'my_post_type'
).