Last active
December 2, 2019 10:07
-
-
Save christiaansnoei/d79b55b7992e424d74dd8242b57f67a2 to your computer and use it in GitHub Desktop.
List all child pages of a parent page in WordPress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| global $post; | |
| $ancestors = $post -> ancestors ?? ''; | |
| if( isset($ancestors) ): | |
| $ancestors = array_reverse($ancestors); | |
| if( isset($ancestors[0]) ): | |
| $current_toplevel_menu_id = $ancestors[0]; | |
| else: | |
| $current_toplevel_menu_id = $post -> ID; | |
| endif; | |
| $args = array( | |
| 'child_of' => $current_toplevel_menu_id, | |
| 'post_type' => $post -> post_type, | |
| 'title_li' => '', | |
| ); | |
| wp_list_pages($args); | |
| endif; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment