WP 固定ページ内孫ページ一覧


<?php 
if(!$post->post_parent == 0):
$args = array(
    'post_parent'=> get_the_ID(),
    'post_type' => 'page'
);
if(count(get_children($args)) > 0):
?>
<ul>
<?php
$parent_id = get_the_ID();
$args = array(
    'posts_per_page' => -1,
    'post_type' => 'page',
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'post_parent' => $parent_id,
);
$common_pages = new WP_Query( $args );
if( $common_pages->have_posts() ):
while( $common_pages->have_posts() ): $common_pages->the_post();
?>
<li><a href="<?php the_permalink(); ?>">
   <?php the_title(); ?>
</a></li>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
</ul>
<?php endif; endif;?>

WP 固定ページ内子ページ一覧
子一覧を取得するものと最初の指定が違うだけです。
この少しの差を見つけるのに苦労しました・・・

参考にさせてもらった記事
WordPressの固定ページで孫ページ(第3階層)の場合だけ出力する

WEB,WP

Posted by admin