walk_page_dropdown_tree() WordPress Function
The walk_page_dropdown_tree() function walks through the pages in a WordPress site and outputs a dropdown menu of those pages. The function takes two arguments: the first is the depth of the pages to include in the menu (e.g. 0 for all pages, 1 for top-level pages only, 2 for top-level and second-level pages, etc.), and the second is an array of arguments to control the output of the menu. The walk_page_dropdown_tree() function is a great way to create a hierarchical navigation menu for a WordPress site. By default, the function will output a menu with all pages in the site, but the depth argument can be used to limit the menu to only top-level pages, or to a specific depth. The function also accepts an array of arguments to control the output of the menu, including the 'id', 'class', and 'selected' attributes.
walk_page_dropdown_tree( mixed $args ) #
Retrieves HTML dropdown (select) content for page list.
Description
See also
- Walker_PageDropdown::walk(): for parameters and return description.
Parameters
- $args
(mixed)(Required)Elements array, maximum hierarchical depth and optional additional arguments.
Return
(string)
Source
File: wp-includes/post-template.php
function walk_page_dropdown_tree( ...$args ) { if ( empty( $args[2]['walker'] ) ) { // The user's options are the third parameter. $walker = new Walker_PageDropdown; } else { /** * @var Walker $walker */ $walker = $args[2]['walker']; } return $walker->walk( ...$args ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.3.0 | Formalized the existing ...$args parameter by adding it to the function signature. |
2.1.0 | Introduced. |