Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Created May 17, 2021 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshwaghmare/79c7eba02397e5d6741431ad770225e0 to your computer and use it in GitHub Desktop.
Save maheshwaghmare/79c7eba02397e5d6741431ad770225e0 to your computer and use it in GitHub Desktop.
Get the function prefix_build_tree() from - https://gist.github.com/02b5611b48f1e7ce397cd191bd44a2cf - Read more at https://maheshwaghmare.com/?p=37686
<?php
function prefix_page_tree_markup( $page_id = 0 ) {
$pages = prefix_get_page_tree( $page_id );
if( empty( $pages ) ) {
if( is_user_logged_in() ) {
echo '<p>No Post Found!</p>';
}
return;
}
echo '<ul>';
foreach( $pages as $page ) {
echo '<li><a href="'.$page['link'].'">'. $page['post_title'] . '</a>';
if( ! empty( $page['children'] ) ) {
echo '<ol>';
foreach( $page['children'] as $child_1 ) {
echo '<li><a href="'.$child_1['link'].'">'. $child_1['post_title'] . '</a>';
if( ! empty( $child_1['children'] ) ) {
echo '<ol>';
foreach( $child_1['children'] as $child_2 ) {
echo '<li><a href="'.$child_2['link'].'">'. $child_2['post_title'] . '</a>';
if( ! empty( $child_2['children'] ) ) {
echo '<ol>';
foreach( $child_2['children'] as $child_3 ) {
echo '<li><a href="'.$child_3['link'].'">'. $child_3['post_title'] . '</a>';
echo '</li>';
}
echo '</ol>';
}
echo '</li>';
}
echo '</ol>';
}
echo '</li>';
}
echo '</ol>';
}
echo '</li>';
}
echo '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment