Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_page_hierarchy [ WordPress Function ]

get_page_hierarchy ( $pages, $page_id = 0 )
Parameters:
  • (array) $pages Posts array.
  • (int) $page_id Parent page ID.
Returns:
  • (array) A list arranged by hierarchy. Children immediately follow their parents.
Defined at:



Order the pages with children under parents in a flat list.

It uses auxiliary structure to hold parent-children relationships and runs in O(N) complexity

Source


<?php
function &get_page_hierarchy( &$pages$page_id ) {
    if ( empty( 
$pages ) ) {
        
$result = array();
        return 
$result;
    }

    
$children = array();
    foreach ( (array) 
$pages as $p ) {
        
$parent_id intval$p->post_parent );
        
$children$parent_id ][] = $p;
    }

    
$result = array();
    
_page_traverse_name$page_id$children$result );

    return 
$result;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics