On this page
Walker::display_element( object $element, array $children_elements, int $max_depth, int $depth, array $args, string $output )
Traverses elements to create list from elements.
Description
Display one element if the element doesn’t have any children otherwise, display the element and its children. Will only traverse up to the max depth and no ignore elements under that depth. It is possible to set the max depth to include all depths, see walk() method.
This method should not be called directly, use the walk() method instead.
Parameters
$elementobject Required-
Data object.
$children_elementsarray Required-
List of elements to continue traversing (passed by reference).
$max_depthint Required-
Max depth to traverse.
$depthint Required-
Depth of current element.
$argsarray Required-
An array of arguments.
$outputstring Required-
Used to append additional content (passed by reference).
Source
File: wp-includes/class-wp-walker.php. View all references
public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
if ( ! $element ) {
return;
}
$id_field = $this->db_fields['id'];
$id = $element->$id_field;
// Display this element.
$this->has_children = ! empty( $children_elements[ $id ] );
if ( isset( $args[0] ) && is_array( $args[0] ) ) {
$args[0]['has_children'] = $this->has_children; // Back-compat.
}
$this->start_el( $output, $element, $depth, ...array_values( $args ) );
// Descend only when the depth is right and there are children for this element.
if ( ( 0 == $max_depth || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
foreach ( $children_elements[ $id ] as $child ) {
if ( ! isset( $newlevel ) ) {
$newlevel = true;
// Start the child delimiter.
$this->start_lvl( $output, $depth, ...array_values( $args ) );
}
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
}
unset( $children_elements[ $id ] );
}
if ( isset( $newlevel ) && $newlevel ) {
// End the child delimiter.
$this->end_lvl( $output, $depth, ...array_values( $args ) );
}
// End this element.
$this->end_el( $output, $element, $depth, ...array_values( $args ) );
}
Related
Uses
| Uses | Description |
|---|---|
| Walker::start_el() wp-includes/class-wp-walker.php | Starts the element output. |
| Walker::start_lvl() wp-includes/class-wp-walker.php | Starts the list before the elements are added. |
| Walker::display_element() wp-includes/class-wp-walker.php | Traverses elements to create list from elements. |
| Walker::end_lvl() wp-includes/class-wp-walker.php | Ends the list of after the elements are added. |
| Walker::end_el() wp-includes/class-wp-walker.php | Ends the element output, if needed. |
Used By
| Used By | Description |
|---|---|
| Walker::display_element() wp-includes/class-wp-walker.php | Traverses elements to create list from elements. |
| Walker::walk() wp-includes/class-wp-walker.php | Displays array of elements hierarchically. |
| Walker::paged_walk() wp-includes/class-wp-walker.php | Produces a page of nested elements. |
| Walker_Comment::display_element() wp-includes/class-walker-comment.php | Traverses elements to create list from elements. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/walker/display_element