Advertisement
Guest User

Untitled

a guest
Nov 25th, 2010
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <?php
  2.  
  3. $defaults = array(
  4. 'depth'         => 1,
  5. 'title_li'      => '',
  6. 'echo'          => 1,
  7. 'exclude'       => 6,
  8. 'sort_column'   => 'menu_order, post_title',
  9. 'sort_order'    => 'asc',
  10. 'link_before'   => '',
  11. 'link_after'    => '');
  12.  
  13. // get all the top level pages
  14. $pages = get_pages($defaults);
  15.  
  16. // loop around all the top level pages
  17. foreach($pages as $page) {
  18.    
  19.     // does this page have children?
  20.     $child_pages = get_pages('child_of='.$page->ID.'&sort_column=post_date&sort_order=desc');
  21.    
  22.     $count = 0;
  23.    
  24.     $page_multi_ar = array();
  25.    
  26.     // current page has children...
  27.     if(count($child_pages)>0) {
  28.         // get the child...
  29.         foreach($child_pages as $child_page)
  30.         {      
  31.             // store the pageid,childpageid => childpage object
  32.             $page_multi_ar[$page->ID][$child_page->ID] = $child_page;
  33.         }
  34.     // top level page              
  35.     } else {
  36.         // store the pageid,0 => page object
  37.         $page_multi_ar[$page->ID][0] = $page;      
  38.     }  
  39. }
  40.  
  41. /*
  42. // so you end up with
  43.  
  44. array[1][0] // top level page
  45. array[2][3] // child of two
  46. array[2][4] // child of two
  47. array[2][5] // child of two
  48. array[6][0] // top level page
  49. array[7][8] // child of eight
  50. */
  51.  
  52. //then foreach around the whole array..
  53.  
  54. $page_multi_ar[1][0] ="top";// top level page
  55. $page_multi_ar[2][3] ="child";// child of two
  56. $page_multi_ar[2][4] ="child";// child of two
  57. $page_multi_ar[2][5] ="child";// child of two
  58. $page_multi_ar[6][0] ="top";// top level page
  59. $page_multi_ar[7][8] ="top";// child of eight
  60.  
  61. echo'<ul>';
  62.  
  63. //print_r($arry_);
  64. foreach($page_multi_ar as $parent_id => $inner_ar) {
  65.    
  66.     $count = 0;
  67.    
  68.     foreach($inner_ar as $id => $data) {
  69.                        
  70.         if($id!=0) {
  71.                        
  72.             if($count==0) {
  73.                
  74.                 echo '<li>parent_id: '.$parent_id.'</li>
  75.                       <ul><li>';
  76.                
  77.             } else {
  78.                
  79.                 echo '<li>';
  80.                
  81.             }
  82.            
  83.             echo'child_id '.$id;               
  84.  
  85.             if($count==sizeof($inner_ar)-1) { echo '</li></ul>'; } else { '</li>'; }           
  86.             $count++;          
  87.         // 0 = parent page         
  88.         } else {           
  89.             echo'<li>parent_id: '.$parent_id.'</li>';                      
  90.         }      
  91.     }
  92. }
  93. echo'</ul>';
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement