Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $defaults = array(
- 'depth' => 1,
- 'title_li' => '',
- 'echo' => 1,
- 'exclude' => 6,
- 'sort_column' => 'menu_order, post_title',
- 'sort_order' => 'asc',
- 'link_before' => '',
- 'link_after' => '');
- // get all the top level pages
- $pages = get_pages($defaults);
- // loop around all the top level pages
- foreach($pages as $page) {
- // does this page have children?
- $child_pages = get_pages('child_of='.$page->ID.'&sort_column=post_date&sort_order=desc');
- $count = 0;
- $page_multi_ar = array();
- // current page has children...
- if(count($child_pages)>0) {
- // get the child...
- foreach($child_pages as $child_page)
- {
- // store the pageid,childpageid => childpage object
- $page_multi_ar[$page->ID][$child_page->ID] = $child_page;
- }
- // top level page
- } else {
- // store the pageid,0 => page object
- $page_multi_ar[$page->ID][0] = $page;
- }
- }
- /*
- // so you end up with
- array[1][0] // top level page
- array[2][3] // child of two
- array[2][4] // child of two
- array[2][5] // child of two
- array[6][0] // top level page
- array[7][8] // child of eight
- */
- //then foreach around the whole array..
- $page_multi_ar[1][0] ="top";// top level page
- $page_multi_ar[2][3] ="child";// child of two
- $page_multi_ar[2][4] ="child";// child of two
- $page_multi_ar[2][5] ="child";// child of two
- $page_multi_ar[6][0] ="top";// top level page
- $page_multi_ar[7][8] ="top";// child of eight
- echo'<ul>';
- //print_r($arry_);
- foreach($page_multi_ar as $parent_id => $inner_ar) {
- $count = 0;
- foreach($inner_ar as $id => $data) {
- if($id!=0) {
- if($count==0) {
- echo '<li>parent_id: '.$parent_id.'</li>
- <ul><li>';
- } else {
- echo '<li>';
- }
- echo'child_id '.$id;
- if($count==sizeof($inner_ar)-1) { echo '</li></ul>'; } else { '</li>'; }
- $count++;
- // 0 = parent page
- } else {
- echo'<li>parent_id: '.$parent_id.'</li>';
- }
- }
- }
- echo'</ul>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement