walk_page_tree() WordPress Function
The walk_page_tree() function is used to walk through all the pages in a WordPress installation. This function is useful for creating a list of all the pages in a WordPress site, or for creating a navigation menu. The walk_page_tree() function takes two arguments: a callback function and a starting page. The callback function is used to process each page in the WordPress site. The starting page is the page from which the walk_page_tree() function will start walking through the pages in the WordPress site.
walk_page_tree( array $pages, int $depth, int $current_page, array $args ) #
Retrieves HTML list content for page list.
Parameters
- $pages
(array)(Required)
- $depth
(int)(Required)
- $current_page
(int)(Required)
- $args
(array)(Required)
Return
(string)
Source
File: wp-includes/post-template.php
function walk_page_tree( $pages, $depth, $current_page, $args ) {
if ( empty( $args['walker'] ) ) {
$walker = new Walker_Page;
} else {
/**
* @var Walker $walker
*/
$walker = $args['walker'];
}
foreach ( (array) $pages as $page ) {
if ( $page->post_parent ) {
$args['pages_with_children'][ $page->post_parent ] = true;
}
}
return $walker->walk( $pages, $depth, $args, $current_page );
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |