Walker::display_element()publicWP 2.5.0

Traverses elements to create list from elements.

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.

Метод класса: Walker{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$Walker = new Walker();
$Walker->display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
$element(объект) (обязательный)
Data object.
$children_elements(массив) (обязательный) (передается по ссылке — &)
List of elements to continue traversing (passed by reference).
$max_depth(int) (обязательный)
Max depth to traverse.
$depth(int) (обязательный)
Depth of current element.
$args(массив) (обязательный)
An array of arguments.
$output(строка) (обязательный) (передается по ссылке — &)
Used to append additional content (passed by reference).

Список изменений

С версии 2.5.0 Введена.

Код Walker::display_element() WP 6.5.2

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