Show child pages on grandchild
-
I have been trying to get child and grandchild pages on the parent page which I’ve managed but now when I go to the child or grandchild page it either doesn’t show or only shows the child pages…
– Parent Page
— Child Page
— Grandchild PageThis is what I’ve got so far;
<?php $pages = get_posts(array( 'post_type' => 'page', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1 )); global $post; ?> <?php $children = get_page_children($post->ID, $pages); ?> <?php foreach ($children as $child): ?> <div class="accordion"> <?php if ($child->post_parent == $post->ID): ?> <div class="parent parent--children"> <a href="<?php echo get_permalink($child->ID); ?>"><?php echo $child->post_title; ?></a> <div class="dropdown_btn"></div> <?php $granchildren = get_page_children($child->ID, $pages); ?> <ul class="parent parent--grandchildren"> <?php foreach ($granchildren as $grandchild): ?> <li> <a href="<?php echo get_permalink($grandchild->ID); ?>"><?php echo $grandchild->post_title; ?></a> </li> <?php endforeach; ?> </ul> </div> <?php endif; ?> </div> <?php endforeach; ?>
If anyone can help please, that would be great!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Show child pages on grandchild’ is closed to new replies.