Created
October 12, 2018 03:47
-
-
Save goranseric/2da4723a5b31e0176be052b836303fc9 to your computer and use it in GitHub Desktop.
show subpages recursively
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
| wpse13669_show_all_children( $post_id, $current_level ) { | |
| $children = get_posts( array( | |
| 'post_type' =>'page', | |
| 'posts_per_page' =>-1, | |
| 'post_parent' => $post_id, | |
| 'order_by' => 'title', | |
| 'order' => 'ASC' ) ); | |
| if ( empty($children) ) return; | |
| echo '<ul class="children level-'.$current_level.'-children">'; | |
| foreach ($children as $child) { | |
| /* Here would be the point where you | |
| do whatever you want to display the | |
| posts. The variable $current_level can | |
| be used if you want to style different | |
| levels in the hierarchy differently */ | |
| echo '<li>'; | |
| echo '<a href="'.get_permalink($child->ID).'">'; | |
| echo apply_filters( 'the_title', $child->post_title ); | |
| echo '</a>'; | |
| // now call the same function for child of this child | |
| show_all_children( $child->ID, $current_level+1 ); | |
| echo '</li>'; | |
| } | |
| echo '</ul>'; | |
| } | |
| show_all_children( $post->ID, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment