Я думаю, что я только что сделал то же самое:
У меня был пользовательский тип записи, называемый «продукт», родитель - это «бренд», а ребенок, по сути, является «товаром бренда».что я положил в свой файл product.php
Это первый запрос на получение дочерних сообщений [items]
<?php $mypages = get_pages( array( 'child_of' => $post->ID, 'post_type' => 'product', 'sort_order' => 'desc' ) );
//So if it is not a parent
if (empty($mypages)){ ?>
//use these styles
<div class="single_item">stuff is happening</div>
//If it is a parent post so has children
<?php ; } else { ?>
//Then Do these things
<div class="brandstuff">showing extra stuffs</div>
<div class="morebrandstuffs">maybe do some extra stuff</div>
//I wanted to add a list of my child pages to my parent page
<?php $mypages = get_pages( array( 'child_of' => $post->ID, 'post_type' => 'product', 'sort_order' => 'desc' ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( 'the_content', $content );
?><div class="item">
<a href="<?php echo get_permalink( $page->ID ); ?>">
<div class="item_thumb"><?php echo get_the_post_thumbnail($page->ID, 'item_thumb'); ?></div>
<?php echo $page->post_title; ?></a>
</div>
<?php
}
?> <?php } ?>