我试图实现主页显示其所有子页面的特征图像,而一些子页面则显示其子页面的特征图像。这是我到目前为止的代码!
<?php
global $post;
if ( is_page() && $post->post_parent ) :
elseif ( is_page() && $post->post_parent && $post->child_page ) : ?>
<?php else : ?>
<?
$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = \'page\' ORDER BY menu_order", \'OBJECT\');
if ( $child_pages ) :
foreach ( $child_pages as $pageChild ) :
setup_postdata( $pageChild );
$thumbnail = get_the_post_thumbnail($pageChild->ID, \'index-thumb\');
if($thumbnail == "") continue; // Skip pages without a thumbnail
?>
<div class="child-thumb">
<?php
echo \'<div class="re-featured-image">\' . get_the_post_thumbnail($pageChild->ID, \'index-thumb\', array(\'class\' => \'img-responsive\', \'id\' => \'img-center\')) . \'</div>\';
echo \'<div class="re-featured-image-title">\' . get_post(get_post_thumbnail_id($pageChild->ID))->post_title . \'</div>\';
echo \'<div class="re-featured-image-caption">\' . get_post(get_post_thumbnail_id($pageChild->ID))->post_excerpt . \'</div>\';
echo \'<div class="re-featured-image-description">\' . get_post(get_post_thumbnail_id($pageChild->ID))->post_content . \'</div>\';
?>
</div>
<?
endforeach;
endif;
?>
<?php endif; ?>