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)


Top ↑

Return

(string)


Top ↑

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.